Python 硒+;Browsermob代理,无法捕获某些HTTPS响应的主体
我需要捕获从BrowserMob代理发送到Selenium浏览器的响应包的主体。BrowserMob只为一些请求(而不是我需要捕获的请求)捕获响应主体,我不知道为什么 我通过python使用Selenium Firefox。我已将BrowserMob证书安装到Firefox 以下是我正在使用的代码:Python 硒+;Browsermob代理,无法捕获某些HTTPS响应的主体,python,selenium,browsermob-proxy,Python,Selenium,Browsermob Proxy,我需要捕获从BrowserMob代理发送到Selenium浏览器的响应包的主体。BrowserMob只为一些请求(而不是我需要捕获的请求)捕获响应主体,我不知道为什么 我通过python使用Selenium Firefox。我已将BrowserMob证书安装到Firefox 以下是我正在使用的代码: from browsermobproxy import Server import time import json server = Server(path="./bmp/bin/browser
from browsermobproxy import Server
import time
import json
server = Server(path="./bmp/bin/browsermob-proxy", options={'port': 8090})
server.start()
time.sleep(1)
proxy = server.create_proxy()
time.sleep(1)
from selenium import webdriver
profile = webdriver.FirefoxProfile()
selenium_proxy = proxy.selenium_proxy()
profile.set_proxy(selenium_proxy)
driver = webdriver.Firefox(firefox_profile=profile)
proxy.new_har("name", options={'captureHeaders': True, 'captureContent': True})
driver.get("http://www.example.com")
# some clicking and key typing here...
time.sleep(20)
print(json.dumps(proxy.har))
server.stop()
driver.quit()
对于我试图检查内容的数据包,我得到以下结果:
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{
"name": "Date",
"value": "Wed, 08 May 2019 19:25:35 GMT"
},
{
"name": "Content-Type",
"value": "application/json;charset=UTF-8"
}
// more headers...
],
"content": {
"size": 8888,
"mimeType": "application/json;charset=UTF-8",
"comment": ""
// NO TEXT FIELD HERE
},
"redirectURL": "",
"headersSize": 814,
"bodySize": 8888,
"comment": ""
}
而HAR文件中的其他一些包(我不感兴趣)在response.content中确实有一个“text”字段
编辑:我通过使用而不是browsermob解决了这个问题。它包括一个脚本机制,允许您过滤数据包并在其上运行任意python代码