Reputation: 75
I need to store my client's table data into database.
There are n number of tables for which they have not provided any table class (directly using just Table_id in web page).
Example:
[table width="100%" border="0" cellpadding="0" cellspacing="0" id="AutoNumber5" style="border-collapse: collapse" bordercolor="#111111"]<br/>
[table width="100%" border="0" cellpadding="0" cellspacing="0" id="AutoNumber4" style="border-collapse: collapse" bordercolor="#111111" ]
If there is a Table Class, obviously i can parse it easily, but there is no class just id is given in table.
I know there would be only one word syntax, except
for (Element table : doc.select("table")
Maybe I could not find it. How to find it ? I have tried
for (Element table : doc.select("table.AutoNumber5")
But it's not working for me.
How to fix this?
Upvotes: 4
Views: 5876
Reputation: 10069
Try this
doc.select("table#AutoNumber5");
It worked for me.
Reference : http://jsoup.org/apidocs/org/jsoup/select/Selector.html
Upvotes: 3
Reputation: 208
jsoup support css selectors and if you know the css it is easy to use like this:
Document doc = Jsoup.connect("http://xxxxxxxx.com/").get();
Elements el = doc.select("#targeted-elemnet-id");
you only need to replace your element id after # sign without space.
Upvotes: 3