5

可能是一个不清楚的问题,所以这里是代码和解释:

    Document doc = Jsoup.parse(exampleHtmlData);

    Elements certainLinks = doc.select("a[href=google.com/example/]");

String exampleHtmlData 包含来自某个站点的已解析 HTML 源。这个网站有很多链接可以引导用户到谷歌。几个例子是:

http://google.com/example/hello 
http://google.com/example/certaindir/anotherdir/something
http://google.com/anotherexample

我想使用 doc.select 函数提取链接中包含 google.com/example/ 的所有链接。我如何用 JSoup 做到这一点?

4

1 回答 1

9

您可以参考SelectorSyntax

Document doc = Jsoup.parse(exampleHtmlData);
Elements certainLinks = doc.select("a[href*=google.com/example/]");
于 2012-06-10T20:57:12.667 回答