我的HTML看起来像这样:
<table cellspacing='0' border='0' width='100%'>
<col align='left' />
<tr>
<td align='left'><font color='#FF0000'>Programming</font></td>
</tr>
</table>
<table cellspacing='0' border='0' width='100%'>
<col align='left' />
<col align='right' />
<tr>
<td align='left'><font color='#000000'>A1000</font></td>
<td align='right'><font color='#008000'>D.Rogers</font></td>
</tr>
</table>
它是本地存储的。我试图弄清楚如何数据刮“编程”,“A1000”和“D.Rogers。我怎么能用Java和Jsoup做这个?
答案 0 :(得分:0)
以下是阅读内容的方法:
for(Element e : doc.select("td font")) {
String text = e.text();
// do something with text
}
答案 1 :(得分:0)
基于帖子中的示例:
String localHtml=" <table cellspacing=\'0\' border=\'0\' width=\'100%\'>\n"+
" <col align=\'left\' />\n"+
" <tr>\n"+
" <td align=\'left\'><font color=\'#FF0000\'>Programming</font></td>\n"+
" </tr>\n"+
" </table>\n"+
" <table cellspacing=\'0\' border=\'0\' width=\'100%\'>\n"+
" <col align=\'left\' />\n"+
" <col align=\'right\' />\n"+
" <tr>\n"+
" <td align=\'left\'><font color=\'#000000\'>A1000</font></td>\n"+
" <td align=\'right\'><font color=\'#008000\'>D.Rogers</font></td>\n"+
" </tr>\n"+
" </table>";
Document doc = Jsoup.parse(localHtml);
System.out.println(doc.select("font[color=#FF0000]").text());
System.out.println(doc.select("font[color=#000000]").text());
System.out.println(doc.select("font[color=#008000]").text());
Programming
A1000
D.Rogers