可能是一个不清楚的问题,所以这里是代码和解释:
Document doc = Jsoup.parse(exampleHtmlData);
Elements certainLinks = doc.select("a[href=google.com/example/]");
字符串 exampleHtmlData 包含来自某个站点的经过解析的 HTML 源。该站点有很多链接,可将用户引导至 google。举几个例子:
http://google.com/example/hello
http://google.com/example/certaindir/anotherdir/something
http://google.com/anotherexample
我想用doc.select函数提取链接中所有包含google.com/example/的链接。我如何使用 JSoup 执行此操作?
最佳答案
可以引用SelectorSyntax .
Document doc = Jsoup.parse(exampleHtmlData);
Elements certainLinks = doc.select("a[href*=google.com/example/]");
关于Java:使用 JSoup 提取其中包含特定单词的所有链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10972167/