Retrieving a string table with JSoup

I'm using JSoup with Android and I have been successful so far. In my initial activity, I referenced the table and each individual cell in the table by code. My question is, how can I get JSoup table results based on some parameter?

For example, if I wanted to get the third row of a table - (get its contents). Any resources other than what the Jsoup site will do as I find it difficult to follow.

thank

+3


source to share


2 answers


You can 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>

      

This is the second row in the table.

+3


source


Try

"table tr: eq (3)"



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

+2


source







All Articles