Гайд Делаем Google reCAPTCHA v2 Solver

Приветствую всех пользователей этого форума.
Сегодня покажу как с помощью selenium решить ту самую гугл капчу(reCAPTCHA v2) Python.

Приступим...

Selenium WebDriverэто программная библиотека для управления браузерами.
WebDriver представляет собой драйверы для различных браузеров и клиентские библиотеки на разных языках программирования, предназначенные для управления этими драйверами.
Подробнее...




Так же нам потребуется скачать драйвер хрома


Python:
import os
import sys
import warnings

import requests
import time
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager

warnings.filterwarnings("ignore", category=DeprecationWarning)
delayTime = 2
audioToTextDelay = 10
filename = 'captcha_audio.mp3'
byPassUrl = 'https://www.google.com/recaptcha/api2/demo'
googleIBMLink = 'https://speech-to-text-demo.ng.bluemix.net/'

option = webdriver.ChromeOptions()
option.add_argument('lang=en')
option.add_argument("--mute-audio")
option.add_argument("--disable-notifications")
option.add_experimental_option("excludeSwitches", ["enable-logging"])
# option.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
option.add_argument(
    "user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1")


def audioToText(mp3Path):
    driver.execute_script('''window.open("","_blank");''')
    driver.switch_to.window(driver.window_handles[1])

    driver.get(googleIBMLink)

    # Upload file

    time.sleep(1)
    driver.execute_script("window.scrollTo(0, 1000);")
    root = driver.find_element_by_id('root').find_elements_by_class_name('dropzone _container _container_large')
    btn = driver.find_element(By.XPATH, '//*[@id="root"]/div/input')
    btn.send_keys(mp3Path)

    # Audio to text is processing

    time.sleep(audioToTextDelay)

    driver.execute_script("window.scrollTo(0, 1000);")

    try:
        driver.find_element_by_class_name('truste_overlay').clear()
    except:
        pass

    text = driver.find_elements(By.XPATH, '//*[@id="root"]/div/div[7]/div/div/div/span')
    result = " ".join([each.text for each in text])
    print("\n[>] Captcha Text: ", result)

    driver.close()
    driver.switch_to.window(driver.window_handles[0])

    return result


def saveFile(content, filename):
    with open(filename, "wb") as handle:
        for data in content.iter_content():
            handle.write(data)


driver = webdriver.Chrome(chrome_options=option, executable_path=r"chromedriver.exe")
driver.get(byPassUrl)

googleClass = driver.find_elements_by_class_name('g-recaptcha')[0]
outeriframe = googleClass.find_element_by_tag_name('iframe')
outeriframe.click()

print("\n[>] Try Bypass reCAPTCHA...")

allIframesLen = driver.find_elements_by_tag_name('iframe')
audioBtnFound = False
audioBtnIndex = -1

for index in range(len(allIframesLen)):
    driver.switch_to.default_content()
    iframe = driver.find_elements_by_tag_name('iframe')[index]
    driver.switch_to.frame(iframe)
    driver.implicitly_wait(delayTime)
    try:
        audioBtn = driver.find_element_by_id('recaptcha-audio-button') or driver.find_element_by_id('recaptcha-anchor')
        audioBtn.click()
        audioBtnFound = True
        audioBtnIndex = index
        break
    except Exception as e:
        pass

if audioBtnFound:
    try:
        while True:
            href = driver.find_element_by_id('audio-source').get_attribute('src')
            response = requests.get(href, stream=True)
            saveFile(response, filename)
            response = audioToText(os.getcwd() + '/' + filename)

            driver.switch_to_default_content()
            iframe = driver.find_elements_by_tag_name('iframe')[audioBtnIndex]
            driver.switch_to.frame(iframe)

            inputbtn = driver.find_element_by_id('audio-response')
            inputbtn.send_keys(response)
            inputbtn.send_keys(Keys.ENTER)

            time.sleep(2)
            errorMsg = driver.find_elements_by_class_name('rc-audiochallenge-error-message')[0]

            if errorMsg.text == "" or errorMsg.value_of_css_property('display') == 'none':
                print("\n[>] Success")

                try:
                    os.remove("captcha_audio.mp3")
                except:
                    pass

                break

            try:
                driver.find_element_by_id('audio-response')
                print("\n[>] Failed")
                break
            except:
                pass


    except Exception as e:
        print(e)
        print('\n[>] Caught. Try to change proxy now.')
else:
    print('\n[>] Button not found. This should not happen.')



Спасибо за внимание!​
 
Последнее редактирование:
Сверху Снизу