I’ve already looked into several Stack Overflow topics with similar questions.
I have the following problem: I have a simple html page, downloaded and saved locally as .html File, I am parsing it with JSoup to read the content of that table. Unfortunately when I look for my table with .select(“table”) it returns me no Elements. Hence I have debugged it, what I could notice is… my body node has one childnode, which appears to be solely String, and thus I assume I can’t find any table node?
Can anyone help me out please?
Here is my code snippet:
for (Element table : doc.select("table.creditsuisse")) {
for (Element row : table.select("tr")) {
for (Element tds : row.select("td")){
for(Element link : row.select("href")){
System.out.println(link.text());
}
System.out.println(tds.text());
}
}
}
And here is how my input File looks like:
<html>
<head>
</head>
<body>
<table class="creditsuisse" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<th>Name</th>
<th style="width:170px;">Funktion</th>
<th style="width:180px;">
Amtsdauer (Seit) </th>
<th style="width:130px;">Alter (Geburtsdatum)</th>
<th style="width:45px;">Neuigkeit</th>
</tr>
<tr>
<td>
<a onclick="document.location='/u/p/al_thani_jassim_hamad_j_j-9293792/credit_suisse_ag_CH-020.3.923.549-1.htm'" href="/u/p/al_thani_jassim_hamad_j_j-9293792/credit_suisse_ag_CH-020.3.923.549-1.htm">Al-Thani Jassim Hamad J.J.</a> * <br>
</td>
<td>
VR-Mitglied
</td>
<td><a onclick="document.location='http://www.moneyhouse.ch/u/pub/credit_suisse_ag_CH-020.3.923.549-1.htm#28.06.2010'" href="/u/pub/credit_suisse_ag_CH-020.3.923.549-1.htm#28.06.2010">2 Jahre (28.06.2010)</a></td>
<td>-</td>
<td align="center"></td>
</tr>
<tr>
<td>
<a onclick="document.location='/u/p/albers_franz-4438178/credit_suisse_ag_CH-020.3.923.549-1.htm'" href="/u/p/albers_franz-4438178/credit_suisse_ag_CH-020.3.923.549-1.htm">Albers Franz</a> * <br>
</td>
<td>
VR-Mitglied
</td>
<td><a onclick="document.location='http://www.moneyhouse.ch/u/pub/credit_suisse_ag_CH-020.3.923.549-1.htm#04.05.1998'" href="/u/pub/credit_suisse_ag_CH-020.3.923.549-1.htm#04.05.1998">14 Jahre (04.05.1998)</a></td>
<td>-</td>
<td align="center"></td>
</tr>
</tbody>
</table>
</body>
</html>
In order to read a local file in
JSoupyou would need to use the parse method that takes aFileobject rather than the one that takes HTML content. Replacewith