When I parsed the URL I got several href
but I want the href
which has title.Kindly let me get the answer
当我解析URL我得到几个href但我想要hrefwhich有title.Kindly让我得到答案
<a href="detailnews.asp?newsid=18318" title="Power shutdown areas in Chennai on 13-04-15">
<a href="detailnews.asp?newsid=18318">
My jsoup CSS query be like this to get the href
我的jsoup CSS查询就是这样得到href
#table13>tbody>tr>td>a
1 个解决方案
#1
2
Change your CSS selector like this: #table13>tbody>tr>td>a[title]
. The "title" in brackets will get you only a
which have a "title" attribute. Some code:
像这样更改CSS选择器:#table13> tbody> tr> td> a [title]。括号中的“标题”将仅为您提供具有“标题”属性的标题。一些代码:
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
}
#1
2
Change your CSS selector like this: #table13>tbody>tr>td>a[title]
. The "title" in brackets will get you only a
which have a "title" attribute. Some code:
像这样更改CSS选择器:#table13> tbody> tr> td> a [title]。括号中的“标题”将仅为您提供具有“标题”属性的标题。一些代码:
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
}