【发布时间】:2018-11-13 04:09:42
【问题描述】:
我尝试从中提取数据的 betIn 网站是 betIn。我已导航到包含当前将在当天比赛的所有球队列表的部分,我正在尝试提取有关团队,但我目前只能获得 13 个团队而不是所有团队。起初我认为将值存储在数组中是问题,因此我选择移动到 ArrayList 但仍然遇到同样的问题下面是我的代码:
public class test {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/user/Desktop/chromedriver");
WebDriver driver = new ChromeDriver();driver.navigate().to("https://sports.betin.co.ke/mobile#/dailyBundle/soccer/1-1000");
List<WebElement> rows = driver.findElements(By.cssSelector(".match-content.table-a.soccer"));
java.util.Iterator<WebElement> row_list = rows.iterator();
ArrayList<String> teams = new ArrayList<>();
ArrayList<String> bets = new ArrayList<>();
while(row_list.hasNext()){
WebElement rowItem = row_list.next();
String unnecessary = rowItem.findElement(By.cssSelector(".match-content__row--info")).getText();
String Content = rowItem.findElement(By.cssSelector(".match-content__info")).getText();
String relevantContent = Content.replace(unnecessary,"");
String bet = rowItem.findElement(By.cssSelector(".bets")).getText();
teams.add(relevantContent);
bets.add(bet);
}
System.out.println("These are the teams \n"+ teams);
System.out.println("The size of teams is "+ teams.size());
System.out.println("These are the odds \n"+ bets);
driver.close();
}
}
【问题讨论】:
标签: java selenium-webdriver web-scraping