python - Selenium Webdriver 和 Jupyter Notebook。find_elements_by_xpath 不在同一个单元格中工作
问题描述
我正在运行下面的代码以从 wunderground.com 抓取一些数据。
lookup_URL = 'https://www.wunderground.com/hourly/us/ny/new-york-city/date/2020-07-28.html'
options = webdriver.ChromeOptions();
options.headless = False
driver = webdriver.Chrome('./chromedriver.exe', options = options)
driver.get(lookup_URL)
rows = driver.find_elements_by_xpath('//td[@class="mat-cell cdk-cell cdk-column-liquidPrecipitation mat-column-liquidPrecipitation ng-star-inserted"]')
如果我在单个单元格中运行该代码,我会得到一个空列表rows
。
但是,如果我rows = driver.find_elements_by_xpath(.......)
之后在不同的单元格中运行这条线,我会得到我需要的数据。
问题是我需要一次执行脚本,而不是两部分。
有谁知道为什么会这样?非常感谢您的帮助!
解决方案
看来你需要等待。
rows = WebDriverWait(driver, 60).until(EC.visibility_of_all_elements_located((By.XPATH, 'xpath_here')))
导入后:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
推荐阅读
- excel - 返回表格excel中的给定值
- angular-material2 - 如何从角材料对话框中删除填充?
- azure - Azure Functions 中的 System.Data.SqlClient 4.6.0
- android - 在列表视图中显示每个线程进度的进度条
- sql - 完全外连接问题 - 几个月没有收入
- python - 正则表达式捕获所有导入语句
- php - 如何在 index.php 中公开我的 Laravel API?
- css - Angular 7 材料数据表列宽和对齐方式
- domain-driven-design - 跨多个实例的事件溯源并发问题
- xamarin.forms - Xamarin 形成未处理的异常:System.Exception: