python - 使用 selenium 的 Web 驱动程序获取冠状病毒数据的问题
问题描述
我正在编写一个 Python 脚本来使用 selenium 的 webdriver从Wordlometers获取冠状病毒数据。我的脚本由以下组成:
class Coronavirus():
def __init__(self):
options = webdriver.ChromeOptions()
options.binary_location = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
chrome_driver_binary = "/usr/local/bin/chromedriver"
self.driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
def get_data(self):
try:
self.driver.get('https://www.worldometers.info/coronavirus/')
table = self.driver.find_element_by_xpath('//*[@id="main_table_countries"]/tbody[1]')
country_element = table.find_element_by_xpath("//td[contains(text(), 'Italy')]")
row = country_element.find_element_by_xpath("./..")
但发生的是 Chrome 会立即打开和关闭。我尝试调试这个脚本,在这里和那里添加一些打印,结果证明该行self.driver.find_element_by_xpath
不允许我打印任何其他内容。我尝试阅读文档,但无法打印任何内容,我该怎么做才能解决这个问题?
非常感谢!
解决方案
推荐阅读
- php - 数组值在空 foreach 中循环后更改
- c# - Migradoc TextFrame 分页符 - 获取当前页面位置
- pysnmp - 使用 PySNMP 获取陷阱发送者的 IP
- azure - Azure CloudBlobContainer.CreateIfNotExists() 引发容器已存在错误并导致网页崩溃
- android - Android构建包大小太大
- google-apps-script - getValue 方法在单元格中获取日期的一些问题
- android - 将 ImageView 放在 ConstraintLayout 中的按钮顶部
- angular - *ngIf 在使用 observable 时在 Angular Material 表中不起作用
- scala - 如何将方法限制为仅用于特定类型?
- cmd - 考虑到无法删除通话记录,如何删除不和谐的PM?