Parse The Inner Html Tags Using JSoup September 14, 2022 Post a Comment I want to find the important links in a site using Jsoup library. So for this suppose we have following code: This is important Solution 1: You can do it this way: File input = new File("/tmp/input.html"); Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/"); Elements headlinesCat1 = doc.getElementsByTag("h1"); for (Element headline : headlinesCat1) { Elements importantLinks = headline.getElementsByTag("a"); for (Element link : importantLinks) { String linkHref = link.attr("href"); String linkText = link.text(); System.out.println(linkHref); } } Copy Taken from the JSoup Cookbook. Share You may like these postsHtmlUnitDriver Does Not Load Javascript When Navigating A Page From An UrlWhy Web Socket Behave Differently On Nodejs ?Java HTMLUnit GetByFirstXPath Not WorkingHow To Post An Array Of Custom Objects With Missing Entries To Struts2 Action Post a Comment for "Parse The Inner Html Tags Using JSoup"
Post a Comment for "Parse The Inner Html Tags Using JSoup"