<dependencies> <dependency> <groupId>net.htmlparser.jericho</groupId> <artifactId>jericho-html</artifactId> <version>3.4</version> </dependency> </dependencies> import net.htmlparser.jericho.*; public class HtmlParserExample { public static void main(String[] args) throws Exception { String html = "<html><body><a href='https://example.com'>Example</a></body></html>"; Source source = new Source(html); Element[] linkElements = source.getAllElements(HTMLElementName.A); for (Element element : linkElements) { String href = element.getAttributeValue("href"); String text = element.getTextExtractor().toString(); System.out.println(text + ": " + href); } } } Example: https://example.com


上一篇:
下一篇:
切换中文