Reputation: 83
When I parsed the URL I got several href
but I want the href
which has title.Kindly let me get the answer
<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
#table13>tbody>tr>td>a
Upvotes: 1
Views: 245
Reputation: 12348
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:
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
}
Upvotes: 2