Extract HTML Table ( span ) tags using Jsoup in Java -
i trying extract td name , span class. in sample code, want extract href in first td "accessory" , span tag in second td.
i want print mouse, is-present, yes keyboard, no dual-monitor, is-present, yes
when use below java code, get, mouse yes keyboard no dual-monitor yes.
how span class name?
html code
<tr> <td class="" width="1%" style="padding:0px;"> </td> <td class=""> <a href="/accessory">mouse</a> </td> <td class="tright "> <span class='is_present'>yes</span><br/> </td> <td class="tright "> <br/> </td>
<tr> <td class="" width="1%" style="padding:0px;"> </td> <td class=""> <a href="/accessory"> keyboard</a> </td> <td colspan="2" class="" style='text-align:center;'> <small>no</small> </td>
<td class="" width="1%" style="padding:0px;"> </td> <td class=""> <a href="/accessory">dual-monitor</a> </td> <td class="tright "> <span class='is_present'>yes</span><br/> </td> <td class="tright "> <br/> </td>
java code
private void printparse(string htmldata){
element table = data.select("table[class="computer_table").first(); iterator<element> ite = table.select("td").iterator(); while(ite.hasnext()){ sysout(ite.next().text()); } }
if table element you need getting span. don't need td becasue can query using span , still same result. below code snippet.
elements span = table.select("span"); (element src : span) { if (src.tagname().equals("span")) system.out.print( src.attr("class") ); }
but make sure got table element.
Comments
Post a Comment