The Artima Developer Community
Sponsored Link

Java Answers Forum
getting the URL's from an HTML page

2 replies on 1 page. Most recent reply: Jul 23, 2002 8:07 PM by Somik Raha

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
DaveC

Posts: 1
Nickname: david79
Registered: May, 2002

getting the URL's from an HTML page Posted: May 6, 2002 6:34 AM
Reply to this message Reply
Advertisement
I am new to java (just playing really) and want to make a java program that shows all the links on a webpage in a list. I have managed to read in the html file but getting the links is proving tricky...any ideas?

Idealy I would like to list URL's and image/video links too.

David


Evgen

Posts: 14
Nickname: evgen79
Registered: May, 2002

Re: getting the URL's from an HTML page Posted: May 6, 2002 7:45 AM
Reply to this message Reply
For this task more efficiently use Perl.

Somik Raha

Posts: 2
Nickname: somik
Registered: Jul, 2002

Re: getting the URL's from an HTML page Posted: Jul 23, 2002 8:07 PM
Reply to this message Reply
Hi Dave
Check HTMLParser (http://htmlparser.sourceforge.net) - a parser written in Java for this very purpose. It is very easy to extract links with this parser - your code will look like this :

HTMLParser parser = new HTMLParser("http://www.yahoo.com");
parser.registerScanners();
HTMLNode node;
for (Enumeration e = parser.elements();e.hasMoreElements();) {
   node = (HTMLNode)e.nextElement();
   if (node instanceof HTMLLinkTag) {
     // This is a link
     HTMLLinkTag linkTag = (HTMLLinkTag)node;
     //.. put your code here to extract data
     // from the link tag
     System.out.println(linkTag.getLink());
   }
}


Regards,
Somik

Flat View: This topic has 2 replies on 1 page
Topic: popup menu on moving image Previous Topic   Next Topic Topic: Calling Methods by name

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use