jsoup解析td标签值

时间:2022-11-03 13:26:56
<tr bgcolor="#F2F7FE"> 
  <td class="nlctd1" width="15%" valign="top"> 
    题名与责任 &nbsp; 
  </td> 
  <td class="nlctd2" align=left > 
    <img src=http://opac.nlc.gov.cn:80/exlibris/aleph/u20_1/alephe/www_f_chi/icon/f-separator.gif alt='Link' border=0 alt=''><A HREF='javascript:open_window("http://opac.nlc.gov.cn:80/F/EUR6D26JQTF3LUHD7H65G45HGLCHUXNF6TQI7IQSQA3KRVEIQ6-35915?func=service&doc_number=005127897&line_number=0011&service_type=TAG");'>英汉—汉英图书馆实用核心词汇&nbsp;[专著]&nbsp;=&nbsp;English-Chinese/Chinese-English glossary of library and information science&nbsp;/&nbsp;邹秀英,舒悦编</A> 
  </td> 
 </tr>


请问使用jsoup想截取出“题名与责任”中的内容“英汉—汉英图书馆实用核心词汇&nbsp;[专著]&nbsp;=&nbsp;English-Chinese/Chinese-English glossary of library and information science&nbsp;/&nbsp;邹秀英,舒悦编”
现在使用:
Elements td = doc.getElementsByAttributeValue("class", "nlctd1");
for (Element element : td) {
  if (tmp.contains("题名与责任")) {
  这里可以定位到“提名与责任”的td标签
  }
}
但如何定位到下一个<td class="nlctd2" align=left >呢?有没有方法可以根据现在的位置截取下一个td标签值呢?谢谢!

3 个解决方案

#1


Elements elements = doc.select("table td:eq(1) a");
for(Element e:elements){
    System.out.println(e.text());
}

#2


使用jsoup读出的文本用System.out.println打印,其中的空格没有问题,但当插入数据库或是写入文件中时,空格就变成了两个?号,请问如何转换字符?谢谢!

#3


nbsp: non-breaking space
Unicode :U+00A0.
UTF-8  : 0xC2 0xA0.

编码的问题。
我把字符串输出到一个utf8编码的文件中,没有任何问题。

#1


Elements elements = doc.select("table td:eq(1) a");
for(Element e:elements){
    System.out.println(e.text());
}

#2


使用jsoup读出的文本用System.out.println打印,其中的空格没有问题,但当插入数据库或是写入文件中时,空格就变成了两个?号,请问如何转换字符?谢谢!

#3


nbsp: non-breaking space
Unicode :U+00A0.
UTF-8  : 0xC2 0xA0.

编码的问题。
我把字符串输出到一个utf8编码的文件中,没有任何问题。