使用Java将网页的源代码存储在字符串中。我想提取源代码中的所有url并输出它们。我对正则表达式之类的东西很糟糕,甚至不知道如何解决这个问题。任何帮助将不胜感激。
不要使用正则表达式 https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454. Use a parser http://java-source.net/open-source/html-parsers like JSoup http://jsoup.org/.
String html = "your html string";
Document document = Jsoup.parse(html); // Can also take an URL.
for (Element element : document.getElementsByTag("a")) {
System.out.println(element.attr("href"));
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)