使用jsoup解析来获取拥有标题的人

时间:2015-04-13 07:27:11

标签: android css parsing jsoup

当我解析网址时,我得到了几个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

1 个答案:

答案 0 :(得分:2)

更改您的CSS选择器,如下所示:#table13>tbody>tr>td>a[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
}