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

2024-04-25 04:31:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Selenium和Python与recaptchaV2交互,以解决图像验证弹出窗口上的质询按钮。但是遇到一些问题。顺便说一下,我使用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, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[title='recaptcha challenge']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#solver-button"))).click()

problem like


Tags: tofromimportbydriverseleniumbechrome
1条回答
网友
1楼 · 发布于 2024-04-25 04:31:11
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, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#solver-button"))).click()

它还检测自动化以便使用

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

相关问题 更多 >