gpt4 book ai didi

python - 无法在 HAR 中获取响应主体,在 Python 中使用 Browsermobproxy + selenium + FireFox

转载 作者:太空宇宙 更新时间:2023-11-04 04:45:02 25 4
gpt4 key购买 nike

from selenium import web driver
from browsermobproxy import Server
from selenium.webdriver.common.by import By
import json
import time


server = Server(r'D:\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat')
server.start()
proxy = server.create_proxy({'captureHeaders': True, 'captureContent': True, 'captureBinaryContent': True})
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)

proxy.new_har('xxx')
driver.get('XXX')
proxy.wait_for_traffic_to_stop(1, 60)

这就是我得到的:

enter image description here

我想从正文中获取响应但失败了,是否需要设置任何参数?

最佳答案

我花了一些时间寻找这个问题的解决方案。

将 captureHeaders 和其他选项从 create_proxy() 调用移至 new_har()。像这样:

from selenium import web driver
from browsermobproxy import Server
from selenium.webdriver.common.by import By
import json
import time


server = Server(r'D:\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat')
server.start()
proxy = server.create_proxy()
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)

proxy.new_har('xxx', options={'captureHeaders': True, 'captureContent': True, 'captureBinaryContent': True})
driver.get('XXX')
proxy.wait_for_traffic_to_stop(1, 60)

关于python - 无法在 HAR 中获取响应主体,在 Python 中使用 Browsermobproxy + selenium + FireFox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49832373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com