找到reCAPTCHA元素并单击它— Python + Selenium

找到reCAPTCHA元素并单击它— Python + Selenium,第1张

找到reCAPTCHA元素单击它— Python + Selenium Solution update (11-Feb-2020)

使用以下二进制文件集:

  • Selenium v3.141.0
  • ChromeDriver v80.0
  • Chrome Version 80.0

您可以使用以下更新的代码块作为解决方案:

from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support import expected_conditions as ECoptions = webdriver.ChromeOptions() options.add_argument("start-maximized")options.add_experimental_option("excludeSwitches", ["enable-automation"])options.add_experimental_option('useAutomationExtension', False)driver = webdriver.Chrome(options=options, executable_path=r'C:WebDriverschromedriver.exe')driver.get("https://www.inipec.gov.it/cerca-pec/-/pecs/companies")WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECtOR,"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']")))WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@id='recaptcha-anchor']"))).click()

Original solution

在https://www.inipec.gov.it/cerca-pec/-/pecs/companies要在reCAPTCHA复选框上
调用的URL中,您需要:click()

诱导WebDriverWait获得所需的帧并切换到该帧。
诱导WebDriverWait使所需的元素可单击。
您可以使用以下解决方案:

        from selenium import webdriver    from selenium.webdriver.common.by import By    from selenium.webdriver.support.ui import WebDriverWait     from selenium.webdriver.support import expected_conditions as EC    from selenium.webdriver.chrome.options import Options    options = webdriver.ChromeOptions()     options.add_argument("start-maximized")    options.add_argument('disable-infobars')    driver = webdriver.Chrome(executable_path=r'C:WebDriverschromedriver.exe', chrome_options=options)    driver.get("https://www.inipec.gov.it/cerca-pec/-/pecs/companies")    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']")))    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@]/div[@]"))).click()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5086401.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存