Jolene
Jolene

Reputation: 149

retrieve information from html using jsoup

I would like to retrieve certain information from html using Jsoup.

These are the items I'd like to retrieve:

<td class="text" nowrap valign="top">&#x2022; 2012年05月14-23日</td>
<td class="text" valign="top"><a href="/events/2012/1205142301.pdf" target="new" class="text">北京、湖南商务考察团</a></td>

I managed to retrieve the 2nd item, which contains a URL and a Chinese title but not the first item. can someone help?

I used the following code to retrieve the 2nd item:

Element image = doc.select("td.text a").get(c);
String v = image.attr("href");
url = ("http://www.s-cba.org.sg" + v);
Log.d("url", url);

Element eventName = doc.select("td.text a").get(c);
event = eventName.text();
Log.d("event", event);

Upvotes: 0

Views: 220

Answers (1)

xiaoyi
xiaoyi

Reputation: 6751

Element link = doc.select("td.text a").first();
Element dateTd = link.parent().previousElementSibling();

String url = link.attr("href")
String title = link.text();
String date = dateTd.text();

Upvotes: 1

Related Questions