繁体   English   中英

使用Jsoup从HTML表中提取数据

[英]Extracting data from HTML table with Jsoup

我正在尝试从以下网站上的表中提取数据。 即俱乐部,场地,开始时间。 http://www.national-autograss.co.uk/february.htm

我在这里有许多使用CSS类表的示例,但是此网站没有。 我尝试使用下面的代码,但似乎未提供任何输出。 任何帮助将不胜感激。

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;


public class Main {

    public static void main(String[] args) {

        Document doc = null;
        try {
            doc = Jsoup.connect("http://www.national-autograss.co.uk/february.htm").get();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Elements elements = doc.select("table#table1"); 
        String name;


        for( Element element : elements ) 
        {
            name = element.text(); 
            System.out.println(name);
        }
}

}

ID应该是唯一的,因此您应该直接使用doc.select("#table1")等等

暂无
暂无

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

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