How to scrape table data from specific site JSOUP

隐身守侯 提交于 2020-04-30 06:29:33

问题


I'm trying to scrape some data from table on this site:https://www.worldometers.info/coronavirus/

Here is the source code of scraper I've tried

 public static void main(String[] args) throws Exception {

    String url = "https://www.worldometers.info/coronavirus/";
    try{
        Document doc = Jsoup.connect(url).get();
        Element table = doc.getElementById("main_table_countries_today");
        Elements rows = table.getElementsByTag("tr");

        for(Element row : rows){
            Elements tds = row.getElementsByTag("td");

            for(int i = 0;i<tds.size();i++){
                System.out.println(tds.get(i).text());
            }
        }

    }catch (IOException e){
        e.printStackTrace();
    }
}

And here is the output China 80,928 +34 3,245 +8 70,420 7,263 2,274 56 Italy 35,713 ....

I would like to scrape only data for one specific country,eg. France. But I don't have any idea how to do it.

来源:https://stackoverflow.com/questions/60755397/how-to-scrape-table-data-from-specific-site-jsoup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!