gpt4 book ai didi

android - 使用 jsoup 解析获取 href 那些有 title 的人

转载 作者:行者123 更新时间:2023-11-29 20:49:14 24 4
gpt4 key购买 nike

当我解析 URL 时,我得到了几个 href,但我想要有标题的 href。请让我得到答案

<a href="detailnews.asp?newsid=18318" title="Power shutdown areas in Chennai on 13-04-15">
<a href="detailnews.asp?newsid=18318">

我的 jsoup CSS 查询是这样获取 href

#table13>tbody>tr>td>a

最佳答案

像这样更改您的 CSS 选择器:#table13>tbody>tr>td>a[title]。括号中的“title”只会为您提供具有“title”属性的a。一些代码:

Document myDocument = Jsoup.connect("http://example.com/").get();

//selects "a" with a "title" attribute
Elements elements = myDocument.select("#table13>tbody>tr>td>a[title]");

for (Element e : elements) {
System.out.println(e.attr("title")); //print contents of "title" attribute

System.out.println(e.attr("href")); //print contents of "href" attribute
}

关于android - 使用 jsoup 解析获取 href 那些有 title 的人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29599937/

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