Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Table Row with JSoup

Tags:

android

jsoup

Im using JSoup with android and so far I have been successful. In my original activity I referenced a table and from that each individual cell in a table by code. My question is how would I have Jsoup get the results of a table based on some parameter?

For example if I wanted to get the 3rd row of a table - ( get its contents ). Any resources beside whats on the Jsoup site would do as I find that hard to follow.

Thanks

like image 906
Katana24 Avatar asked Dec 29 '25 01:12

Katana24


2 Answers

You could do something like this:

    String html = "<table id=\"myTable\"><tr><td>First</td></tr><tr><td>Second</td></tr><tr><td>Third</td></tr></table>";
    Document doc = Jsoup.parse(html);
    System.out.println(doc.select("#myTable").select("tr").get(1));

Output:

<tr>
 <td>Second</td>
</tr>

That is the second row in the table.

like image 79
B. Anderson Avatar answered Jan 01 '26 15:01

B. Anderson


Try

"table tr:eq(3)"

http://jsoup.org/cookbook/extracting-data/selector-syntax

like image 40
stefan bachert Avatar answered Jan 01 '26 15:01

stefan bachert