简体   繁体   English

JSoup从列表Java中选择选项

[英]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() ). 如果要获取将由选定的HTML代码生成的文本,则应使用text()方法,而不是toString()方法(由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 . 而不是[id=identifier]您只需编写#identifier

So try with 所以尝试

Elements options = doc.select("#objectlist > select > option ");
for (Element option : options){
    System.out.println(option.text());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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