使用 jsoup 解析获取 href 那些有 title 的人
Get href those who have title using jsoup parsing
当我解析 URL 时,我得到了几个 href
但我想要 href
其中有 title.Kindly 让我得到答案
<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
}
当我解析 URL 时,我得到了几个 href
但我想要 href
其中有 title.Kindly 让我得到答案
<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
}