Kri Mar Kri Mar - 18 days ago 5
Android Question

How to select links from this table with JSOUP?

I have a table like this:

<table class=firstclass>
<tr>
<td><a href....></a></td>
</tr>
<tr>
<td><a href....></a></td>
</tr>
<tr>
<td><a href....></a></td>
</tr>


I have other tables in this page, so I suppose that I have to use something like:

doc.select("td.firstclass > a[href]");


but it does not work.

I solved with this:

Element table = doc.select("table.firstclass").first(); //gets a table with the class "first class"
Elements links = table.select("a[href]");
for (Element link : links) {

String textlink= link.text();
String urllink= link.attr("abs:href");
));

}
// ...

Answer

Using "td.firstclass" is implying that your TD will have the class "firstclass".. which is why you get 0 results

You should do something like..

Document doc = ....; //however you get your document

Element table = doc.select("table.firstclass").first(); //gets a table with the class "first class"
Elements links = table.select("a[href]");

And from there you can process your links however you want

Comments