问题
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