简体   繁体   中英

jsoup table to get a particular element

Document doc = Jsoup.connect(studentprofiles).get();
Element tables = doc.select("table");
Elements myTdsstudent = tables.select("tr td:eq(1)");

I am able to get all the details one after another in the eq(1).

In the example:

Table:    
GK   99    
NS   88    
PS   55

I have in HTML Table when I do eq(0) I get GK,NS,PS. when I do eq(1) I get 99 88 55.

Is there a way so that I can read using JSOUP as

gk=99
ns=88
PS=55

Right now I am getting as 2 different array of strings.

Elements myTdsstudent = tables.select("tr");

now iterate over myTdsstudent and use this

for (Element myTdsstudentIterator: myTdsstudent) {
    System.out.println(myTdsstudentIterator.select("td:eq(0)") + " = " + myTdsstudentIterator.select("td:eq(1)"));
}

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