如何使用jsoup获取信息

时间:2015-01-10 13:25:29

标签: java html parsing tags jsoup

我有这个HTML

<td rowspan="3" class="event start"> <a href="/search/1065650;1/note">INFO1<br>DETAIL1 DETAIL2<br>INFO2</a> </td> 

如何使用jsoup获取INFO1和INFO2?

1 个答案:

答案 0 :(得分:0)

尝试类似的东西:

Document doc = Jsoup.connect(url).get();
Elements td=doc.select("td.event.start");
Elements a = td.first().getElementsByTag("a");
String [] words = a.text().split(" ");
System.out.println(words[0]+" "+words[3]);

经过测试:

&#13;
&#13;
<!doctype html>
<html>
<body>
<td rowspan="3" class="event start"> 
 <a href="/search/1065650;1/note">
  INFO1<br>DETAIL1 DETAIL2<br>INFO2
  </a> 
</td> 
</body>
</html>
&#13;
&#13;
&#13;