首页 > 解决方案 > 在 BeautifulSoup/Selenium Scraper 中使用部分匹配

问题描述

我正在尝试从该页面https://www.flashscore.co.uk/cricket/抓取数据。

主队具有以下任一属性:

<div class="event__participant event__participant--home">KSKS</div>

<div class="event__participant event__participant--home fontBold">Legends of Rupganj</div>

我原以为以下内容可以让我使用部分比赛来抓取所有主队,但它不会返回任何结果。没有错误。

homeTeam = container.find('div[class*="event__participant event__participant--home"]').text if container.find('div[class*="event__participant event__participant--home"]') else ''

我究竟做错了什么?

标签: pythonseleniumbeautifulsoup

解决方案


在 Selenium-Python 中,我会做这样的事情:

for home_team in driver.find_elements(By.CSS_SELECTOR, "div[class*='event__participant event__participant--home']"):
    print(home_team.text)

这给了我以下 O/P :

Sydney Sixers
Perth Scorchers
Brisbane Heat
Sydney Sixers
Brisbane Heat
Melbourne Stars
Melbourne Renegades
Brisbane Heat
Adelaide Strikers
Sydney Sixers
Sydney Thunder

推荐阅读