python - 在 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 ''
我究竟做错了什么?
解决方案
在 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
推荐阅读
- powershell - 使用类似于 curl 的 Invoke-WebRequest 测量响应时间
- sql - RDF + OWL 推理
- java - spring.core 的这个模块定义有什么问题?
- vba - 使用 Column to Match 加速从数据中提取行的宏
- cakephp - 为直通表上的关联数据生成表单
- gmail-api - 使用 Gmail API 发送的邮件在发送到 Gmail 地址时被标记为可疑
- javascript - nodejs 如何在没有多线程的情况下实现更好的 http 请求性能?
- python - Python 中的 Facebook API 错误:纬度和经度必须采用带符号的十进制度格式,例如 37.484531,-122.148061
- android - Android 进度条未显示
- javascript - 将对象数组映射到动态数组数组