Parse The Inner Html Tags Using Jsoup
I want to find the important links in a site using Jsoup library. So for this suppose we have following code: This is important
This is important Solution 1:
You can do it this way:
Fileinput=newFile("/tmp/input.html");
Documentdoc= Jsoup.parse(input, "UTF-8", "http://example.com/");
ElementsheadlinesCat1= doc.getElementsByTag("h1");
for (Element headline : headlinesCat1) {
ElementsimportantLinks= headline.getElementsByTag("a");
for (Element link : importantLinks) {
StringlinkHref= link.attr("href");
StringlinkText= link.text();
System.out.println(linkHref);
}
}
Taken from the JSoup Cookbook.
You can do it this way:
Fileinput=newFile("/tmp/input.html");
Documentdoc= Jsoup.parse(input, "UTF-8", "http://example.com/");
ElementsheadlinesCat1= doc.getElementsByTag("h1");
for (Element headline : headlinesCat1) {
ElementsimportantLinks= headline.getElementsByTag("a");
for (Element link : importantLinks) {
StringlinkHref= link.attr("href");
StringlinkText= link.text();
System.out.println(linkHref);
}
}
Taken from the JSoup Cookbook.
Post a Comment for "Parse The Inner Html Tags Using Jsoup"