【发布时间】:2019-11-26 15:23:48
【问题描述】:
我正在尝试通过 python 使用 Chrome 和 QUIC 导出 HAR 文件。 使用 TLS1.3 的 QUIC 协议 - 所以我只能使用带有客户端证书的协议
- 我找到了this 的答案(使用代理服务器),但代理没有启用 QUIC 的客户端证书,因此所有 HAR 文件都是 HTTP1.1 协议。
- 我找到了this 代码(使用 chrome 配置文件设置),但我无法使用此代码导出 HAR 文件。
基本上,我想将这两个代码合并为一个。 使用 chrome 配置文件导出 HAR 文件(以启用 TLS1.3、HTTPS 和 QUIC)
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
和
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()
【问题讨论】:
标签: python-3.x proxy selenium-chromedriver har