Extracting absolute URL from a website using Jsoup

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class LinkChecker {
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
        try {
            Document document = Jsoup.connect("http://www.amazon.com").get();
         Elements links = document.select("a");
         int validLinkCounter = 0;
         for (Element link : links) {
          if(!link.absUrl("href").isEmpty()) {
           System.out.println(link.absUrl("href"));
           validLinkCounter++;
           }
          }
         System.out.println("Number of links = " + validLinkCounter);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

One Response to Extracting absolute URL from a website using Jsoup

  1. very nice post liked reading it got very effective information thanks for sharing details on virtual assistant http://www.ivrguru.com for virtual assistant

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s