[Python] Solving Captcha manually while pasing a website

Discussão em 'Python' iniciado por Stack, Fevereiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to parse a website using google search results. The returned URL of the page from the google search results is correct, but while trying to parse it, the website shows a captcha that needs to be solved. Is it possible to display the captcha back to user to solve it and then continue the parsing of that page?

    The html file of the first parsing had this script that contains the captcha details:

    <script>
    var recaptchaReady = function () {
    grecaptcha.render('iCaptcha', {'sitekey': 'XXXXXXXXXXXXXXXXX-XXXXXXXXX'});
    captchaRendered = true;
    };

    window.onload = function () {
    if (!window['captchaRendered']) {
    var captchaElement = document.getElementById('iCaptcha'),
    captchaFallback = document.getElementById('captcha-noscript'),
    captchaFallbackText = document.getElementById('captcha-fallback-text');

    captchaElement.innerHTML = captchaFallback.textContent;
    captchaFallbackText.textContent = captchaFallback.getAttribute('data-text');
    }
    };
    </script>


    This is the Python code that I am using to get the URL that I am looking for:

    from googlesearch import search
    from bs4 import BeautifulSoup

    search_result_list = list(search(query, tld="de", num=1, stop=1, pause=1))

    headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0", "Accept-Encoding":"gzip, deflate", "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "DNT":"1","Connection":"close", "Upgrade-Insecure-Requests":"1"}

    page = requests.get(search_result_list[0], headers=headers)

    with open("output1.html", "w") as file:
    file.write(page.text)

    Continue reading...

Compartilhe esta Página