没有devtools我怎么能得到哈尔?当我尝试使用这个代码时,我增加了这个错误:
代码
chrome.devtools.network.getHAR(function(result) {
var entries = result.entries;
if (!entries.length) {
Console.warn("Recarregue a pagina, ou inicie o stream");
}
for (var i = 0; i < entries.length; ++i) {
console.log(entries[i]);
}
});错误:
Uncaught TypeError: Cannot call method 'getHAR' of undefined 我把这段代码输入到background.js中
清单:
{
"name": "Download Stream",
"version": "1.0",
"minimum_chrome_version": "10.0",
"description": "Efetua o download do stream",
"background": { "scripts": ["background.js"] },
"page_action" :
{
"default_icon" : "icon-19.png",
"default_title" : "Download Stream"
},
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
],
"icons" : {
"48" : "icon-48.png",
"128" : "icon-128.png"
},
"manifest_version": 2
}发布于 2015-08-16 13:40:54
不能简单地使用Chrome来生成HAR文件。但是,您可以使用BrowsermobProxy从Chrome中捕获HAR,使用Selenium从Chromedriver中捕获HAR。
下面是一个在BrowsermobProxy和Selenium中使用色驱动器的示例:
from browsermobproxy import Server
from selenium import webdriver
import os
import json
import urlparse
server = Server("path/to/browsermob-proxy")
server.start()
proxy = server.create_proxy()
chromedriver = "path/to/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
url = urlparse.urlparse (proxy.proxy).path
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--proxy-server={0}".format(url))
driver = webdriver.Chrome(chromedriver,chrome_options =chrome_options)
proxy.new_har("http://stackoverflow.com", options={'captureHeaders': True})
driver.get("http://stackoverflow.com")
result = json.dumps(proxy.har, ensure_ascii=False)
print result
proxy.stop()
driver.quit()查看速度剖面以使生活更轻松。
https://stackoverflow.com/questions/18039479
复制相似问题