Reputation: 89
Maybe someone could help me with exracting information from html using jsoup?
Information needed is 23.90
<tr>
<td class="leftcell" valign="top">
<div onclick=
"ShowHideTravelDetails('bookingPrice_TaxesToggleBox',
'bookingPrice_TaxesToggleIcon', '/Images');" class="productheader">...</div>
</td>
<td class="rightcell emphasize" align="right"
valign="bottom">$23.90</td></tr>
I can see it in few places in the html doc. I've tried using
Elements taxes = doc.select("td.rightcell.emphasize");
but it is not working.
Also tried extracting info as from table:
Elements table = doc.select("table[class=selectiontable]");
Elements rows = table.get(0).select("td[class^=rightcell emphasize]");
for (Element row : rows) {
Elements tds = row.select("td");
System.out.println(tds.get(13));
Upvotes: 3
Views: 956
Reputation: 4509
Try like this I assume that you have a code like this . You need to do nested level iteration to get the result .
public class Test {
public static void main(String[] args) {
String html ="<table class=\"selectiontable\">\n" +
"<tr>\n" +
" <td class=\"leftcell\" valign=\"top\">\n" +
" <div onclick=\n" +
" \"ShowHideTravelDetails('bookingPrice_TaxesToggleBox', \n" +
"'bookingPrice_TaxesToggleIcon', '/Images');\" class=\"productheader\">...</div>\n" +
"</td>\n" +
"<td class=\"rightcell emphasize\" align=\"right\" \n" +
"valign=\"bottom\">$23.90</td></tr>\n" +
"</table>";
Document document = Jsoup.parse(html);
Elements elements = document.select(".selectiontable");
for (Element element :elements){
for (Element row : element.select("tr")) {
Elements tds = row.select("td");
if (tds.size() > 1) {
System.out.println(tds.get(1).text());
}
}
}
}
}
output:
$23.90
Upvotes: 1