绕过reCAPTCHA google TimeoutException:消息

2024-05-04 04:10:06 发布

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

我正在编写一段代码,使用带有selenium的python的“web抓取”来获取信息

我有一个问题要通过recaptcha(图),下面我将解释我所做的:

我的代码:

# bypass reCAPTCHA google

# Load selenium components
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.support.ui import Select
from webdriver_manager.chrome import ChromeDriverManager
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import UnexpectedAlertPresentException
from selenium.webdriver.chrome.options import Options

# based on:
# code source -> https://github.com/ohyicong/recaptcha_v2_solver/blob/master/recaptcha_solver.py#L27

#recaptcha libraries
import speech_recognition as sr
import urllib
import pydub
import time

#system libraries
import os
import sys
import random
import time

def delay ():
    time.sleep(random.randint(2,3))

# initialize the driver
driver = webdriver.Chrome(executable_path="/bin/chromedriver")

#get method to launch the URL
driver.get("http://www.detran.sp.gov.br/wps/portal/portaldetran/cidadao/veiculos/servicos/pesquisaDebitosRestricoesVeiculos")

print('Loading webpage...')

# identifying the link with the help of link text locator
driver.find_element_by_css_selector('img.ico_miniatura').click()


print('Input info placa...')
inputElement = driver.find_element_by_id("viewns_Z11_419E11C0M0UL30QQMNV10N0045_:placa")
inputElement.send_keys('EFP1075')

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.CSS_SELECTOR, "span#recaptcha-anchor"))).click()
driver.switch_to.default_content()

#time.sleep(5)

# HERE START THE PROBLEM:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#recaptcha-audio-button"))).click()


#WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "recaptcha-audio-button"))).click()
#WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".rc-audiochallenge-play-button button")))

# get the mp3 audio file
#src = driver.find_element_by_id("audio-source").get_attribute("src")
#print(src)

在这一行中,我遇到了一个问题:

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

错误:回溯

Traceback (most recent call last):
  File "scrape.py", line 60, in <module>
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#recaptcha-audio-button"))).click()
  File "/home/andsilva/anaconda3/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

我不明白,可能找不到元素button#recaptcha-audio-button 在此图中,显示下载音频的按钮。 enter image description here

有人知道如何解决这个问题吗

提前谢谢

安德烈


Tags: tofromimportbydriverseleniumbuttonelement