- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我需要使用 Selenium Chrome 驱动程序和 browsermob 代理获取 POST 请求的响应正文内容。目前,虽然我可以在浏览器网络流量中看到响应,但在我阅读文件 HAR 输出时,此内容并未包含在我的文件 HAR 输出中。我如何才能捕获响应流量? (抱歉,编程新手,看不到很多 BMP 的 python 文档)
server.start() proxy = server.create_proxy() chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--proxy-server={0}".format(proxy.proxy)) driver = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=chrome_options) proxy.new_har("req", options={'captureHeaders': True,'captureContent':True}) driver.get('https://www.example.com/something') result_har = json.dumps(proxy.har, ensure_ascii=False) with open("haroutput.har", "w") as harfile: harfile.write(result_har) server.stop() driver.quit()
最佳答案
您可以通过 proxy.har['log']['entries']
中具有相同名称的 key 获取请求和响应。响应的内容在 entry['response']['content']
但在您必须将 'captureContent':True
添加到 proxy.new_har
调用的 option
字典中之前。
例子:
from browsermobproxy import Server
server = Server("./bin/browsermob-proxy")
server.start()
proxy = server.create_proxy()
from selenium import webdriver
co = webdriver.ChromeOptions()
co.add_argument('--proxy-server={host}:{port}'.format(host='localhost', port=proxy.port))
driver = webdriver.Chrome(executable_path="chromedriver", chrome_options=co)
proxy.new_har('req',options={'captureHeaders': True,'captureContent':True})
driver.get(url)
proxy.har # returns a HAR
for ent in proxy.har['log']['entries']:
_url = ent['request']['url']
_response = ent['response']
_content = _response['content']['text']
关于python - BrowserMob Proxy Python - 如何获取响应主体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50550496/
一些服务器可以响应 Via header 。为了实验的纯洁性,我想去掉它。如何使用 python 上的包装器为 Browsermob-proxy 制作它?为了更好地理解,我将生成代码:对不起我的英语!
我正在尝试使用 BrowserMob proxy监控 WebDriver(Selenium) 浏览器发送的请求。 我实例化代理: server = new ProxyServer(localP
有人熟悉使用 BrowserMob 代理吗?我需要一些帮助。 https://github.com/lightbody/browsermob-proxy/blob/master/README.md 我
我正在使用代理来排除第三方资源。但我对以 https 开头的所有资源都有问题。您能提出任何解决方案吗?例如,我试图从 http://linkedin.com 中排除 static.licdn.co
我无法在我的 Selenium 项目中设置 BrowserMob 代理。喜欢described in BrowserMob Proxy github page我将其导入到我的代码中: public c
我开始在 Selenium 上编写一些测试,并认为如果我能够在登录我们的网站时获得性能指标,那就太好了。我遇到了 BrowserMob-Proxy。我首先从 Lightbody 的 github 页面
我需要在一个测试场景中再创建一个响应过滤器。但现在当我这样做时,两个过滤器同时工作。如何在不停止当前浏览器实例的情况下停止或覆盖前一个浏览器实例? 代码示例: proxy.addResponseFil
我正在尝试使用 Browsermob 代理检查网站上的网络流量。通过运行以下命令:我发现代理服务器拒绝连接: “代理服务器拒绝连接”“firefox 配置为使用拒绝连接的代理。” 我还没有找到在 py
我使用 Watir 正确设置了 BrowserMob 代理,它正在捕获流量并保存 HAR 文件;但是,它没有做的是它没有持续捕获流量。所以以下是我要实现的目标: 转到首页 单击链接转到我需要等待某些事
我需要使用 Selenium Chrome 驱动程序和 browsermob 代理获取 POST 请求的响应正文内容。目前,虽然我可以在浏览器网络流量中看到响应,但在我阅读文件 HAR 输出时,此内容
我想在 Protractor 测试套件运行期间捕获我的应用程序发出的网络请求。 BrowserMob Proxy看起来是一个很好的工具。 我想使用 browsermob-node 将 BrowserM
Selenium Webdriver 2.42.2,browsermob-proxy Beta 9,Windows 7/Firefox 我正在尝试调用 browsermob-proxy API 来捕获
我正在尝试使用 browsermob-proxy 来监控 selenium 测试的所有请求和响应。在我的例子中,我在 jenkins 上的 docker 图像中使用 py.test 框架运行 sele
我正在寻找为 browsermob 配置上游代理,最好是在 python 或 shell 脚本中以编程方式配置。 browsermob 的 python 绑定(bind)看起来不包含上游代理配置命令或
我正在使用 selenium 3.0.2 和 browsermob 代理 0.7.1 来捕获网络数据。我得到的只是一个空的 JSON。我的代码是: server = Server("/Users/de
问这个问题时,我可能看起来很天真。对于我们的一些测试场景,我需要检索各种 HTTP 代码。现在我知道 Selenium 不能单独完成,我们必须使用第三方资源 - 可能是像 Browsermob 这样的
我在使用 Selenium 的测试自动化项目中使用 BrowserMob 代理 2.0-beta-8。我正在测试的页面使用的是 https,我需要重写用户代理 header 。对于普通的 http 请
我正在尝试设置 browsermob 以在我的 selenium 项目中工作。我一直在寻找一种使用 ChromeOptions 来设置代理的方法,但所有消息来源都告诉我对其他所有内容都使用 Chrom
我正在尝试将 browsermob 代理嵌入到我的 selenium (chrome) 框架中以进行 UI 自动化测试,以拦截响应和其他网络。 描述: Selenium webdriver 使用 br
具有依赖项的 Maven/Java 项目: net.lightbody.bmp browsermob-core 2.1.4 test junit junit
我是一名优秀的程序员,十分优秀!