selenium获取请求和响应

1.下载browsermob-proxy

2.代码实现

python 复制代码
    server = Server(r"D:\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat")
    server.start()
    proxy = server.create_proxy()
    options = Options()
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--proxy-server={0}'.format(proxy.proxy))
    driver = webdriver.Chrome(options=options)
    driver.maximize_window()
    proxy.new_har("log", options={'captureHeaders': True, 'captureContent': True, 'captureBinaryContent': True})
    driver.get("https://www.cnblogs.com/mrjade")
    result = proxy.har
    for entry in result['log']['entries']:
        _url = entry['request']['url']
        print(_url)
        # entry每一个请求URL都对应着一个response,我们只需要判断URL找出自己想找的那个JSON就好
        if _url.__contains__("你想要的那个链接"):  # 如果两个相等,则可能是我们想要的数据,因为这个URL可能有多个,
            # 在后面拿到数据之后再进一步判断即可
            _response = entry['response']
            _content = _response['content']
            print(_content)
    server.stop()
    driver.quit()
相关推荐
weixin_4196583111 小时前
基于 Trae 和 Postman-MCP-Server 接口自动化测试
测试工具·postman
weixin_419658311 天前
Postman-MCP-Server 的构建以及在 Trae 中的配置方法
测试工具·postman
测试员周周2 天前
【AI测试系统】第6篇:需求扔进去,3 分钟出测试用例?AI测试系统的 RAG 知识增强实战
人工智能·python·功能测试·测试工具·测试用例
测试员周周2 天前
【AI测试功能2】AI功能测试的“不可确定性“难题与应对思路:从精确断言到统计判定的完整方案
大数据·人工智能·python·功能测试·测试工具·单元测试·测试用例
测试员周周3 天前
【AI测试系统】第5篇:AI 编码工具抛硬币?我们用 LangGraph 做了个“确定性+AI”的测试系统(附自愈架构)
人工智能·python·功能测试·测试工具·架构·langchain·单元测试
弹简特3 天前
【精通Postman接口测试】02-集合变量|环境变量|全局变量,批量运行原来这么简单(附图文+CLI实战)
测试工具·接口测试·postman
DevilSeagull3 天前
电脑上安装的服务会自动消失? 推荐项目: localhostSCmanager. 更好管理你的服务!
测试工具·安全·react·vite·localhost·hono·trpc
Python大数据分析@4 天前
浏览器自动化工具 Selenium,Playwright,Puppeteer 做爬虫有哪些弊病?
爬虫·selenium·自动化
弹简特4 天前
【精通Postman接口测试】01-基础理论+安装使用+项目实战+接口关联(万字图文,零基础保姆级)
测试工具·postman·接口关联
武帝为此4 天前
【Selenium 屏幕截图】
python·selenium·测试工具