简体   繁体   中英

JSoup selecting options from the list java

Trying to get the information that is in the option tags but with my path it returns the info with the tags.

    Connection conn = Jsoup.connect("http://timetables.cit.ie:70/studentset.htm");
    conn.timeout(5000); // timeout in milliseconds
    Document doc = conn.get();  
    String title = doc.title(); 


    Elements tBody = doc.select("[id=objectlist] > select > option ");
    System.out.println(tBody);

If you want to get text which will be generated by selected HTML code you should use text() method instead of toString() method (which is invoked implicitly by println() ).

Also if you want to get text from each option individually you need to iterate over all selected options.

And instead of [id=identifier] you can simply write #identifier .

So try with

Elements options = doc.select("#objectlist > select > option ");
for (Element option : options){
    System.out.println(option.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