在本网页中
https://www.iadb.org/en/transparency/sanctioned-firms-and-individuals
有一个可单击的按钮,称为“导出到Excel”,如下图所示。
我需要从Python中点击它(以便下载Excel)。
我试过这个代码:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
driver = webdriver.Chrome(r"./driver/chromedriver")
driver.execute("get", {'url': 'https://www.iadb.org/en/transparency/sanctioned-firms-and-individuals'})
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.ID, "Export to excel"))).click()
但我得到了这个错误:
追溯(最近一次调用):
File ~/opt/anaconda3/lib/python3.9/site-packages/spyder_kernels/py3compat.py:356 in compat_exec
exec(code, globals, locals)
File ~/Library/CloudStorage/GoogleDrive-glevorato@provenir.com/Shared drives/Provenir AI Team/Data Science/Data Science/09 AML/OFAC - SDN.py:359
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.ID, "Export to excel"))).click()
File ~/opt/anaconda3/lib/python3.9/site-packages/selenium/webdriver/support/wait.py:95 in until
raise TimeoutException(message, screen, stacktrace)
TimeoutException
谁能告诉我,我做错了什么?
1条答案
按热度按时间f87krz0w1#
有两个问题,我认为:
1.您的定位器策略不正确,请更改如下:
1.您需要先单击
AcceptCookies
按钮,因为此元素与所需元素重叠,您可能会得到ElementClickInterceptedException
。请参阅下面的代码以供参考。请查看以下工作代码: