简体   繁体   中英

Extracting data from HTML table with Jsoup

I am trying to extract the data from the table on the following website. Ie Club, venue, start time. http://www.national-autograss.co.uk/february.htm

I have got many examples on here working that use a css class table but this website doesn't. I have made an attempt with the code below but it doesn't seem to provide any output. Any help would be very much appreciated.

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")等等

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