爬取地址:https://www.worldometers.info/coronavirus/
数据内容:
部分代码:
ChromeDriver chromeDriver = new ChromeDriver();
chromeDriver.get("https://www.worldometers.info/coronavirus/");
WebElement content = chromeDriver.findElement(By.id("main_table_countries_yesterday"));
List<WebElement> tr2 = content.findElements(By.tagName("tr"));
ArrayList<String> arrayList = new ArrayList<>();
for (int i = 0; i < tr2.size(); i++) {
WebElement webElement = tr2.get(i);
if (i!=0&&i!=240){
if (!webElement.getText().equals("")){
List<WebElement> td = webElement.findElements(By.tagName("td"));
StringBuilder sb = new StringBuilder();
for (int j = 0; j < td.size(); j++) {
if (j != 15) {
WebElement element = td.get(j);
sb.append(element.getText()).append(";");
}
}
arrayList.add(sb.toString());
}
}
}