简体   繁体   中英

Jsoup select command operation

I am new to Jsoup.

I am able to use select command

Elements media = doc.select("[src]");

if you see this : en.wikipedia.org/wiki/States_and_territories_of_India . In that I want to have all the Names in States of India only. But there are other tables also , when I do doc.select("area[title]"); I am getting all the table information . so I am looking if in select I can tell how it is used to only for a particular table.

I think Jsoup might not address this if that is the case,can you please tell me how to achieve this

Try something like this

Element indiaTable = doc.select("table").get(2); //India table is the third (index is 2) table on page
Elements myTds = indiaTable.select("td:eq(0)"); //The states are the first column

//or you can replace the two lines of code above with this

Elements myTds = doc.select("table.wikitable td:eq(0)");



for (Element td: myTds ) {
    System.out.println(td.text());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM