【发布时间】:2021-06-29 19:13:30
【问题描述】:
我正在尝试从网站上抓取一些文章,在此之前,我需要在 Python 中使用 Selenium 单击“Cookies Agree”。
但不幸的是,我不断收到 TimeoutException 或 NoSuchElementException!
我发现点击按钮在 iframe 中,所以我切换到它并点击了同意按钮。
homepage = 'link'
driver.maximize_window()
driver.get(homepage)
driver.implicitly_wait(5)
driver.switch_to.frame('location')
try:
consent = wait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'classname')))
consent.click()
except TimeoutException :
print('timeoutexception')
driver.switch_to.default_content()
但我仍然无法通过 TimeoutException 错误。
我做错了什么......?!
【问题讨论】:
-
请查看我的回答