我有一個像這樣的表,我想要解析以獲取數據代碼值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