我知道在 Jsoup 中,当你想找到某个带有链接的元素时,你可以这样做:
Document doc = Jsoup.parse(text);
Element links = doc.select("[href]");
然而,这会获取页面中每个网站的所有链接...
但是如果我有多个链接,而且我只想检索专门链接到 google 的链接怎么办。例如:
<a href="http://www.google.com">Google</a>
<a href="http://www.bing.com">Bing</a>
<a href="http://www.google.com">Another Google</a>
而且我希望它只包含其中包含 google 的内容。我试着做这样的事情:
Element links = doc.select("[href=\"http://www.google.com\"]");
但这行不通...有人有什么建议吗?
最佳答案
你有没有简单地试过这个:
Element links = doc.select("[href=http://www.google.com]");
//Or,
Element links = doc.select("a[href=http://www.google.com]");
//Or with the 'attribute contains' form, the most likely to work:
Element links = doc.select("a[href*=google]");
关于android - 你如何使用 JSoup 查找元素(HTML 解析)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10009225/