Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 硒+;Browsermob代理,无法捕获某些HTTPS响应的主体_Python_Selenium_Browsermob Proxy - Fatal编程技术网

Python 硒+;Browsermob代理,无法捕获某些HTTPS响应的主体

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

我需要捕获从BrowserMob代理发送到Selenium浏览器的响应包的主体。BrowserMob只为一些请求(而不是我需要捕获的请求)捕获响应主体,我不知道为什么

我通过python使用Selenium Firefox。我已将BrowserMob证书安装到Firefox

以下是我正在使用的代码:

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代码