TA的每日心情 | 擦汗 前天 09:07 |
---|
签到天数: 527 天 连续签到: 4 天 [LV.9]测试副司令
|
1测试积点
chrome得到的请求,53个
browsermob-proxy得到的请求,48个
我的代码
- # _*_ 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("关闭浏览器")
复制代码
|
|