Avatar billede fredand Forsker
25. april 2003 - 15:03 Der er 10 kommentarer og
1 løsning

How to check a the filelist in a map at a URL?

Hello!

Does any one know how to check what files ther is in a map say for eg. at http://www.google.com/logos/

Best regards

Fredrik
Avatar billede arne_v Ekspert
25. april 2003 - 15:10 #1
You want to parse teh HTML and find all URL links and/or image URL's ?
Avatar billede arne_v Ekspert
25. april 2003 - 15:12 #2
HTML parsing sucks due to the "pragmatic interpretation" of the
HTML standards by most HTML writers.

If it is valid XHTML 1.0 it is easy to parse with an XML parser.

If it is "look OK in MSIE" HTML, then it will be hard work
to write a good parser.
Avatar billede fredand Forsker
25. april 2003 - 15:15 #3
No, I actually hope that I could make a:

File dir = new File("http://www.google.com/logos/");
String[] files = dir.list();

But it doesn't seems to work.
Fredrik
Avatar billede =maddog= Nybegynder
25. april 2003 - 15:19 #4
I don't think you can get a directory listing on a remote server. Perhaps if you have explicit rights to read the folder contents, but I can't see how it could be done.
Avatar billede arne_v Ekspert
25. april 2003 - 15:19 #5
No.

You will need to get the HTML (similar to your last question)
and parse it for links.
Avatar billede fredand Forsker
25. april 2003 - 15:23 #6
Ok, I see!

Give me answers so I can give away the points!

Thanks!

Fredrik
Avatar billede =maddog= Nybegynder
25. april 2003 - 15:25 #7
i don't want any points. at least not 25. I didn't really help you in any way...
Avatar billede arne_v Ekspert
25. april 2003 - 15:28 #8
I am not sure how much my answer is worth either.

But anyway.
Avatar billede arne_v Ekspert
25. april 2003 - 15:29 #9
As a side note: you can list files for an FTP URL.
Avatar billede fredand Forsker
25. april 2003 - 15:39 #10
For me it was a good help!

Best regards Fredrik
Avatar billede carstenknudsen Nybegynder
26. april 2003 - 13:59 #11
If you load the contents you have read into a JEditorPane you can easily walk through all tags of a specific type, say, <a>. Here is a snippet of code I use in a simple browser to find all hyperlinks.
        JEditorPane pane = ...;
    Document document = pane.getDocument();
    if ( document instanceof HTMLDocument ) {
        HTMLDocument htmldoc = (HTMLDocument)document;
        HTMLDocument.Iterator iterator = htmldoc.getIterator( HTML.Tag.A );
        iterator.next();
        while ( iterator.isValid() ) {
        AttributeSet attr = iterator.getAttributes();
        boolean found = false;
        Enumeration enum = attr.getAttributeNames();
        while ( enum.hasMoreElements() && ! found ) {
            Object name = enum.nextElement();
            if ( name.equals( HTML.Attribute.HREF ) ) {
            found = true;
            Object value = attr.getAttribute( name );
            boolean problem = false;
            URL url = null;
            try {
                url = new URL( (String)value );
            } // try
            catch ( MalformedURLException murle ) {
                problem = true;
            } // catch
            if ( ! problem ) {
                JButton button = new UpDownJButton( (String)value );
                menu.add( button );
                button.addActionListener( buttonListener );
            } // if
            } // if
        } // while
        iterator.next();
        } // while
    } // if
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester