为什么browsermob-proxy得到的request,会比chrome得到的request少?
# _*_ coding:utf-8 _*_from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from browsermobproxy import Server
import json
from time import sleep
try:
# 启动代理
server = Server(r'/Users/renguanyu/app/browsermob-proxy/2.1.4/bin/browsermob-proxy')
server.start()
proxy = server.create_proxy()
# 启动浏览器
chrome_options = Options()
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--proxy-server={0}'.format(proxy.proxy))
# chrome_options.add_argument('--headless') # 无头模式
browser = webdriver.Chrome(options=chrome_options)
browser.implicitly_wait(60)
# 监听结果
url = 'https://www.baidu.com/'
proxy.new_har(options={
'captureContent': True,
'captureHeaders': True
})
browser.get(url)
# 打印network
result = proxy.har
log = result["log"]
entries = log["entries"]
list = []
for entrie in entries:
request = entrie["request"]
request_url = request["url"]
response = entrie["response"]
status = response["status"]
dict = {
"url": request_url,
"status": status
}
list.append(dict)
# sleep(30)
print("request_list",list)
print("request_list_length",len(list))
finally:
print("执行完毕,准备关闭程序")
# sleep(3)
# 关闭代理和浏览器
proxy.close()
print("关闭代理")
# browser.close()
browser.quit()
print("关闭浏览器")
回答
问题解决了,跟我本地的权限系统有关,如果是测试环境,就不会出现缺失请求的状况
以上是 为什么browsermob-proxy得到的request,会比chrome得到的request少? 的全部内容, 来源链接: utcz.com/a/58284.html