[Python] Unable to locate #audio-source element in captcha solver using DrissionPage

Discussão em 'Python' iniciado por Stack, Outubro 5, 2024.

  1. Stack

    Stack Membro Participativo

    I'm working on automating the solving of a reCAPTCHA using Python, pydub, and DrissionPage. I've managed to reach the point where the audio challenge is presented. However, I'm having trouble locating the #audio-source element to download the audio file. When I attempt to find the element, I receive the following error:

    Error solving CAPTCHA: 没有找到元素。 method: ele() args: {'locator': '#audio-source', 'index': 1, 'timeout': 10}

    I've verified that the audio button is clicked successfully, but the #audio-source element isn't being found, even after increasing the timeout.

    Here is the relevant part of my code:

    import os
    import urllib.request
    import random
    import time
    import pydub
    import speech_recognition as sr
    from DrissionPage import ChromiumPage

    class RecaptchaSolver:
    def __init__(self, driver):
    self.driver = driver

    def solveCaptcha(self):
    # Locate the iframe containing the reCAPTCHA
    iframe_inner = self.driver("@title=reCAPTCHA")
    time.sleep(0.1)

    # Click the reCAPTCHA checkbox
    iframe_inner('.rc-anchor-content', timeout=1).click()

    # Click on the audio button
    iframe = self.driver("xpath://iframe[contains(@title, 'recaptcha')]")
    iframe('#recaptcha-audio-button', timeout=1).click()
    time.sleep(1) # Wait for the audio challenge to load

    # Try to find the audio source element
    self.driver.wait.ele_displayed('#audio-source', timeout=10)
    src = iframe('#audio-source').attrs['src']

    # Download the audio and process it
    temp_dir = os.getenv("TEMP") if os.name == "nt" else "/tmp/"
    path_to_mp3 = os.path.join(temp_dir, f"{random.randint(1, 1000)}.mp3")
    urllib.request.urlretrieve(src, path_to_mp3)
    # More code for audio processing follows...



    What I've Tried: Increasing the timeout for locating #audio-source. Verifying that the audio button is clicked successfully. Adding explicit waits and delays. Despite these efforts, the element still isn't found. Has anyone encountered a similar issue when automating reCAPTCHA audio challenges? How can I ensure that the #audio-source element is properly located?

    Additional Information: I'm using DrissionPage with a Chromium-based browser. The audio button is clicked successfully, but the audio source element never seems to appear. The page I'm working with is the Activision login page.

    Continue reading...

Compartilhe esta Página