[英]jsoup extracting data from a table
我有一个html文件,我需要使用jsoup从中提取部门名称。
Document doc = Jsoup.connect("http://directory.binghamton.edu/directory/directory.deptlist").get();
System.out.println(doc);
Elements departments = doc.select("deptlist");
for (Element department : departments) {
System.out.println(department.text());
}
我已经做了类似的事情,但是没有用。
查看源代码:http://directory.binghamton.edu/directory/directory.deptlist
谢谢。
开始了!
Document doc = Jsoup.connect("http://directory.binghamton.edu/directory/directory.deptlist").get();
Elements departments = doc.select("table#deptlist a"); // Select all 'a' in a 'table'-tag with id 'deptlist'
String name;
for( Element element : departments ) // Iterate over all Elements available
{
name = element.text(); // Save the plaintext (no html) of the element
System.out.println(name); // Simple output (as an example)
}
在代码中,选择一个标签“ deptlist”而不是表格。
如果要选择id=deptlist
所有元素(在我的示例中,仅选择具有该id的表),则可以使用以下选择器: doc.select("#deptlist")
。
在这里查找更多信息: JSoup选择器API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.