You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用requests绕过invisible reCaptcha验证?

问题:使用requests绕过invisible reCaptcha失败,寻求高效替代方案

我正在用requests库开发一款高效的网站扫描器,在模拟浏览器的GET/POST请求时,遇到了invisible reCaptcha的拦截,导致无法完成正常交互。

我已经尝试了以下操作:

  • 完全模拟网络监视器捕获的GET和POST请求头与参数
  • 使用requests.Session对象保存会话Cookie
  • 尝试用pypasser获取reCaptcha V3响应,但返回的结果无法让请求通过

试过第三方验证码破解API,但这类API要么依赖webdriver,要么需要提供密钥,而当前场景下密钥为空,无法使用。另外也了解过selenium的解决方案,但selenium运行效率太低,希望能避开它。

以下是我写的测试代码:

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)

代码能返回响应,但不是预期的正确结果,请问有没有不依赖selenium的高效方法绕过这个invisible reCaptcha?


内容的提问来源于stack exchange,提问作者tomer dror

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 00:30:42