我正在尝试从cricinfo网站上收集数据,并编写了一种接受播放器名称并显示其相应数据的方法。
[如果您看到此方法,则使用玩家名称并显示其所有数据。
我的要求是为所有玩家显示完整的计分卡,而不是仅显示一名玩家的数据。
public static void displayData(WebDriver driver, String input)
{
WebElement player = driver.findElement(By.xpath("//a[contains(text(),'"+input+"')]"));
String player_name = player.getText();
WebElement bowled_by = driver.findElement(By.xpath("//a[contains(text(),'"+input+"')]//parent::div//following-sibling::div[@class='cell commentary']"));
String bowled_by_detail = bowled_by.getText();
List<WebElement> score_card = driver.findElements(By.xpath("//a[contains(text(),'"+input+"')]//parent::div//following-sibling::div[@class='cell runs']"));
System.out.println(player_name);
System.out.println(bowled_by_detail);
for(int i=0;i<score_card.size();i++)
{
String values = score_card.get(i).getText();
System.out.print(values + " | ");
}System.out.println();
}
displayData(driver,“ HM Amla”);
HM Amlac沙玛·布姆拉6 | 9 | 16 | 1 | 0 | 66.66 |
就像使用Python的BeautifulSoup一样,您可以使用Jsoup