我有一个问题,在某些网站上使用Selenium和browsermob的测试变得非常慢。下面是我设置服务器和代理的当前代码:
server = Server(path_browsermob)
server.start()
proxy = server.create_proxy()
co = webdriver.ChromeOptions()
co.add_argument('--proxy-server={host}:{port}'.format(host='localhost', port=proxy.port))
driver = webdriver.Chrome(path_driver, chrome_options=co)我已经读到过加速测试的一种方法是使用EC证书而不是RSA。但是,如何使用上面的代码激活ECC?
发布于 2018-09-13 05:02:46
在了解到browsermob-proxy和SSL证书的这个“问题”后,我也有同样的问题。
仔细研究一下browsermob-proxy python库,在创建代理时,看起来好像有任何extra parameters被传递给了URL。
这样,您就应该能够将API documentation中概述的任何参数传递给create_proxy()。
下面是我的代码片段(尽管我不确定如何查询代理以查看它是否实际设置)。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from browsermobproxy import Server
#Create proxy server
bmp_server_opts = {"port": 8080}
bmp_server = Server("browsermob-proxy-2.1.4/bin/browsermob-proxy", options = bmp_server_opts)
bmp_server.start()
time.sleep(1)
proxy_server = bmp_server.create_proxy({"useEcc": True, "trustAllServers": True})
time.sleep(1)
selenium_proxy = proxy_server.selenium_proxy()
#Create Firefox options
firefox_opts = webdriver.FirefoxOptions()
firefox_profile = webdriver.FirefoxProfile()
firefox_opts.set_headless()
firefox_profile.set_proxy(selenium_proxy)
#Fire up a Firefox browser
firefox_browser = webdriver.Firefox(firefox_profile = firefox_profile, firefox_options = firefox_opts)
wait_load = WebDriverWait(firefox_browser, 10)
proxy_server.new_har("103398", options = {'captureHeaders': True, "captureContent": True})尽管将useEcc设置为true仍然存在一些问题,我最终添加了trustAllServers,它忽略了所有的ssl检查,但我不确定如果你需要接近真实的用户体验,这是正确的方法。无论哪种情况,我仍然有相当慢的SSL/TLS连接。
https://stackoverflow.com/questions/52194266
复制相似问题