[Python] Bypassing invisible reCaptcha with requests

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to make a scanner to a website using requests so the bot would be more efficient, and when I went over the Network Monitor to see the GET and POST request when emulating the process, I noticed that there's an invisible reCaptcha that prevents me to continue the process using the requests lib.

    I tried simulating the exact GET and POST requests that I saw in the Network Monitor including doing it with the Session Object and saving the cookies I get, but the reCaptcha is what (I think) prevents me from actually keeping the interaction working. I tried looking for third party API, but what I understand it only works when you actually open the webdriver or you get a key to provide in the payload which in this case is not needed because the key is empty. Also I saw some solutions using selenium but I'm trying to avoid using it because it takes more time and I need to be as efficient as possible.

    That's the code I tried to start the first steps:

    import requests
    from pypasser import reCaptchaV3

    headers = {
    'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
    'Accept-Encoding' : 'gzip, deflate, br',
    'Accept-Language':'en-US,en;q=0.5',
    'Connection':'keep-alive',
    'Host':'agendamentosonline.mne.gov.pt',
    'Sec-Fetch-Dest':'document',
    'Sec-Fetch-Mode':'navigate',
    'Sec-Fetch-Site':'none',
    'Sec-Fetch-User':'?1',
    'Upgrade-Insecure-Requests':'1',
    'User-Agent':'what my broswer provides me'
    }

    session = requests.Session()
    resp = session.get('https://agendamentosonline.mne.gov.pt/AgendamentosOnline/app/scheduleAppointmentForm.jsf',headers=headers)
    cookies = requests.utils.cookiejar_from_dict(requests.utils.dict_from_cookiejar(session.cookies))
    recaptcha_response_1 = reCaptchaV3('https://www.recaptcha.net/recaptcha/api2/anchor?ar=1&k=6LcKSTIfAAAAAEAxSrS8rAFiDux_eX2DBPnCXGkR&co=aHR0cHM6Ly9hZ2VuZGFtZW50b3NvbmxpbmUubW5lLmdvdi5wdDo0NDM.&hl=en&v=pn3ro1xnhf4yB8qmnrhh9iD2&size=invisible&cb=1ozwitjudoci')
    recaptcha_response_2 = reCaptchaV3('https://www.recaptcha.net/recaptcha/api2/anchor?ar=1&k=6Ld7jDcgAAAAAJTt2PDioLNT69IwwEPvlhqa94K7&co=aHR0cHM6Ly9hZ2VuZGFtZW50b3NvbmxpbmUubW5lLmdvdi5wdDo0NDM.&hl=pt-PT&v=pn3ro1xnhf4yB8qmnrhh9iD2&size=normal&cb=ans33lqyh70u')
    print(recaptcha_response_1) #
    print(recaptcha_response_2) #

    payload_1 = {
    'javax.faces.partial.ajax': 'true',
    'javax.faces.source': 'scheduleForm:tabViewId:dataNascimento',
    'javax.faces.partial.execute': 'scheduleForm:tabViewId:dataNascimento',
    'javax.faces.behavior.event': 'blur',
    'javax.faces.partial.event': 'blur',
    'scheduleForm': 'scheduleForm',
    'javax.faces.ViewState': '-7004941669221712425:6117221410156700201',
    'scheduleForm:tabViewId:ccnum': '****',
    'scheduleForm:tabViewId:dataNascimento_input': '***',
    'scheduleForm:tabViewId_activeIndex': '0',
    'g-recaptcha-response': '',
    'scheduleForm:respV2': ''
    }

    resp = session.post('https://agendamentosonline.mne.gov.pt/AgendamentosOnline/app/scheduleAppointmentForm.jsf',headers=headers,data=payload_1,cookies =cookies)

    print(resp.text)


    It does give me a response just a different response than the one I should get when it works

    Continue reading...

Compartilhe esta Página