我有一个像这样的表,我想要解析以获取数据代码值row.id
和表的第二和第三列。JSoup如何解析表3行
<table>
<tr class="id" data-code="100">
<td></td>
<td>18</td>
<td class="name">John</td>
<tr/>
<tr class="id" data-code="200">
<td></td>
<td>21</td>
<td class="name">Mark</td>
<tr/>
</table>
我想打印出来。
100, 18, John
200, 21, Mark
我曾尝试以下建议,从这个线程,但它不是选择什么how to parse a table from HTML using jsoup
URL url = new URL("http://www.myurl.com");
Document doc = Jsoup.parse(url, 3000);
Element tables = doc.select("table[class=id]");
for(Element table : tables)
{
System.out.println(table.toString());
}
编辑:使用Jsoup.connect(也尝试过),而不是解析()
Document doc = null;
try
{
doc = Jsoup.connect("http://www.myurl.com").get();
}
catch (IOException e)
{
e.printStackTrace();
}
表没有一个类别“id” ......?尝试tr [class = id] – 2015-02-24 13:20:59
它不工作,我已经尝试过'doc.select(“table tr.id”)''和table tr [class = id]“)' – Clumbsyx 2015-02-24 13:25:22
这里工作正常...错误是大概在前两行...... println(doc)输出什么东西? – 2015-02-24 13:35:23