android - 你如何使用 JSoup 查找元素(HTML 解析)?

标签 android html-parsing jsoup element

我知道在 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/

相关文章:

android - 一个 ScrollView 只能有一个 child

android - ExpandableListView 中的复选框

java - HTML ParserDelegator 和 ParserCallback 不起作用

python - 获取 <li> 中 <a> 标签的 href

java - Jsoup选择表数据

java - 将 HTML 解析为对象

Android 根应用程序回显不适用于设备驱动程序

android - Android 资源的 XML 注释可以自动复制到 R 中吗?

java - 在雅虎财经上使用 JSoup 提取表数据

java - jSoup从网页获取数据并显示在JavaFX TableView中