如何使用 Selenium 和 Python 单击recaptchaV2 的解决挑战按钮

问题描述

我正在尝试与recaptchaV2交互使用Selenium和Python解决图像验证弹出窗口上的挑战按钮。但遇到一些问题。顺便说一句,我使用buster chrome扩展程序绕过recaptcha。希望可以帮助我。谢谢你~

from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import webdriverwait
from selenium.webdriver.support import expected_conditions as EC
chrome_options = webdriver.ChromeOptions()
chrome_options.add_extension('~/Library/Application Support/Google/Chrome/Default/Extensions/mpbjkejclgfgadiemmefgebjfooflfhl/1.1.0_0.crx')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.google.com/recaptcha/api2/demo")
webdriverwait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://www.google.com/recaptcha/api2/anchor']")))
webdriverwait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"span#recaptcha-anchor"))).click()
driver.switch_to.default_content()
webdriverwait(driver,"iframe[title='recaptcha challenge']")))
webdriverwait(driver,"button#solver-button"))).click()

problem like

解决方法

chrome_options = webdriver.ChromeOptions()

是过时的使用选项。

from selenium.webdriver.chrome.options import Options
chrome_options = Options()

还有音频按钮

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#recaptcha-audio-button"))).click()   

不是

WebDriverWait(driver,"button#solver-button"))).click()

它还可以检测自动化,所以使用

chrome_options.add_argument('--disable-blink-features=AutomationControlled')