# _*_ 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("关闭浏览器")
问题解决了,跟我本地的权限系统有关,如果是测试环境,就不会出现缺失请求的状况
你需要把所有请求对比。
比如本地缓存影响,比如请求拆分的影响等等