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



我正在尝试与repatchaV2交互。使用Selenium和Python解决图像验证弹出窗口上的挑战按钮。但遇到了一些问题。顺便说一句,我使用buster铬扩展来绕过recatcha。希望能帮助我。谢谢~

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

像这样的问题

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')

邪恶公司在[挑战]中更改了类名

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[title='recaptcha challenge expires in two minutes']")))
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
driver.get('https://www.google.com/recaptcha/api2/demo')
element_present = driver.find_element(By.XPATH, '//*[@title="reCAPTCHA"]')
driver.switch_to.frame(element_present)
element_present = EC.presence_of_element_located((By.XPATH, '//*[@id="recaptcha-anchor"]/div[1]'))
WebDriverWait(driver, 15, poll_frequency=POLL_FREQUENCY).until(element_present).click()
driver.switch_to.default_content()
time.sleep(5)
element_present = driver.find_element(By.XPATH, "/html/body/div[2]/div[4]/iframe")
driver.switch_to.frame(element_present)

try:
buttonHolderElement = driver.find_element(By.XPATH, '//*[@id="rc-imageselect"]/div[3]/div[2]/div[1]/div[1]/div[4]')
actions = ActionChains(driver)
actions.move_to_element(buttonHolderElement)
actions.click(buttonHolderElement)
actions.perform()
except:
pass