Extracting Links From Html
I am trying to extract links from HTML. I am using the following regular expression href=\'([^\']*)\' Which is extracting unnecessary links. How can I write a regular expression t
Solution 1:
Parsing HTML with regex is unnecessarily overcomplicated. Regex is the wrong tool for the job. Just use a normal HTML parser like Jsoup. It allows you to select HTML elements by normal CSS selectors.
Document document = Jsoup.parse(html);
Elements links = document.select("a.l"); // Select all <a class="l"> elements.
for (Element link : links) {
System.out.println(link.absUrl("href"));
}
Post a Comment for "Extracting Links From Html"