我在android中使用Jsoup for Html Parsing。这是我要解析的html表:
<TR><TD><INPUT TYPE="RADIO" NAME="lccp_trndtl" VALUE="12708NZM KCG YNNYNYNYA"ONCLICK="return farefill('12708NZM KCG YNNYNYNYA','12708','NZM ',0,0,1,0,1,0,1,0,0,0,0)" CHECKED>12708</TD>
I need the value of <td> here i.e 12708
。我正在使用以下代码来达到我的目的:
Document doc = Jsoup.parse(htmlPage.trim());
Elements links = doc.select("table tr td input");
if(links != null && links.size() != 0)
Log.v("",String.valueOf(links.size()));
else
Log.v("","Size of links is 0");
for (Element link : links)
{
String linkHref = link.attr("href");
Log.v("",linkHref);
String linkText = link.text();
Log.v("",linkText);
}
我搜索了很多,但没有找到问题的解决方案。请帮帮我。谢谢。
答案 0 :(得分:2)
尝试这种方式它将打印您所需的输出
String s="<TR><TD><INPUT TYPE=\"RADIO\" NAME=\"lccp_trndtl\" VALUE=\"12708NZM KCG YNNYNYNYA\" ONCLICK=\"return farefill('12708NZM KCG YNNYNYNYA','12708','NZM ',0,0,1,0,1,0,1,0,0,0,0)\" CHECKED>12708</TD>";
Document doc = Jsoup.parse(s.trim());
Elements links = doc.getAllElements();
if(links != null && links.size() != 0)
Log.v("output",String.valueOf(links.size())+" "+ links.get(0).text());
else
Log.v("output","Size of links is 0");