[英]Use jsoup drawing html table
I'm reading a html file using jsoup. 我正在使用jsoup读取html文件。 I want to show the html table,how can I do that?
我想显示html表,该怎么办?
I'm a beginner with jsoup - and a not that experienced java developer. 我是jsoup的初学者-而不是经验丰富的Java开发人员。 :)
:)
public class test {
public static void main(String[] args) throws IOException {
// TODO 自動產生的方法 Stub
File input = new File("D://index.html");//從一個html文件讀取
Document doc = Jsoup.parse(input,"UTF-8");
//test
Elements trs = doc.select("table").select("tr");
for(Element e : trs) {
System.out.println("-------------------");
System.out.println(e.text());
}
}
}
Without knowing jsoup, I guess you should descend into the html structure step by step, like this: 在不了解jsoup的情况下,我想您应该逐步进入html结构,如下所示:
...
//test
Elements tables = doc.select("table");
for (Element table : tables) {
for (Element row : table.select("tr")) {
for (Element e : row.select("td")) {
// output your td-contents here
System.out.println("-------------------");
System.out.println(e.text());
}
}
}
...
The advantage of this approach is that you have more control over drawing separators between the HTML Elements. 这种方法的优点是您可以更好地控制HTML元素之间的图形分隔符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.