使用Java在网页上查找链接

ala*_*lan 2 java regex hyperlink

使用Java具有存储在字符串中的网页的源代码.我想提取源代码中的所有url并输出它们.我对正则表达式等很糟糕,并且不知道如何处理这个问题.任何帮助将不胜感激.

Bal*_*usC 6

不要使用正则表达式.使用像JSoup这样的解析器.

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"));
}
Run Code Online (Sandbox Code Playgroud)