chrome-browser“--host-rules”选项不起作用?

时间:2017-12-14 14:08:41

标签: python selenium selenium-chromedriver chromium

下午好!

尝试在Ubuntu / Selenium(3.8.1)+ ChromeDriver(2.34.522913)+ Chromium(63.0.3239.84)+ Python(3.5)中使用--host-rules选项。并且它无法正常工作。

这是代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--host-rules "MAP * localhost"')
service_log_path = "~/tmp/chromedriver.log"
service_args = ['--verbose']
driver = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=chrome_options, service_args=service_args, service_log_path=service_log_path)
driver.get('http://google.com')

并加载html页面。但我已将所有主机映射到localhost! (localhost上没有代理)

在日志中一切正常:

  

[1,002] [INFO]:启动chrome:/ usr / bin / chromium-browser --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable- hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials = SiteIsolationExtensions / Control --host-rules“MAP * localhost”--ignore-certificate-errors --load-extension = / tmp / .org.chromium.Chromium.nrmJ0s / internal --log-level = 0 --metrics-recording-only --no-first-run --password-store = basic --remote-debugging-port = 12837 --test-type = webdriver --use-mock-keychain --user-data-dir = / tmp / .org .chromium.Chromium.v4TEyv数据:,

任何想法如何使其发挥作用?

3 个答案:

答案 0 :(得分:1)

Answering my own question:

Right code:

chrome_options.add_argument('--host-rules=MAP * localhost')

Without quotes around map rule. Thanks to chromium dev team for help.

答案 1 :(得分:0)

试试这个

chrome_options.add_argument('--host-rules="MAP * localhost"')

答案 2 :(得分:0)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--host-rules="MAP * localhost"')
service_log_path = "/Users/.../.../chromedriver.log" # <= bug is here check your path
service_args = ['--verbose']
driver = webdriver.Chrome('/Users/.../.../chromedriver', chrome_options=chrome_options, service_args=service_args, service_log_path=service_log_path)
driver.get('http://google.com')