简体   繁体   中英

Is there are any way to make browsermob-proxy serve HTTPS request?

I use Selenium's ChromeDriver in order to test loading time with certain js file. And for that I used browsermob-proxy python server. Approach is

  1. Start proxy server
  2. Block certain website via blacklist function.
  3. Open Chrome driver with an argument proxy-server

    chrome_options = webdriver.ChromeOptions()
    proxy_url = urlparse(Crawler.proxy.proxy).path
    chrome_options.add_argument('--proxy-server=%s' % proxy_url)
    Crawler.proxy.blacklist(".*my-js-lays-here.*", 200)
    Crawler.driver = webdriver.Chrome(path, chrome_options=chrome_options)

Problem is that my proxy can't handle HTTPS requests and this results in forever loading website. I searched all the way throught browsermob-proxy documentation, but didn't find any code example on how to handle https requests.

Try to accept the certs and if it still doesn't work change your proxy server settings

from selenium.webdriver import DesiredCapabilities

...

capabilities = DesiredCapabilities.CHROME.copy()
capabilities['acceptSslCerts'] = True
capabilities['acceptInsecureCerts'] = True

driver = webdriver.Chrome(options=chrome_options,
    desired_capabilities=capabilities,
    executable_path=config.CHROME_PATH)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM