栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

找到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()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/426717.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号