gpt4 book ai didi

Java:使用 JSoup 提取其中包含特定单词的所有链接?

转载 作者:太空狗 更新时间:2023-10-29 15:38:40 25 4
gpt4 key购买 nike

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

    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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com