簡體   English   中英

鉻瀏覽器“--host-rules”選項不起作用?

[英]chromium-browser “--host-rules” option doesn't work?

下午好!

嘗試在 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 頁面。 但我已將所有主機映射到本地主機! (本地主機上沒有代理)

在日志中一切正常:

[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 數據:,

任何想法如何使它工作?

回答我自己的問題。 正確的代碼:

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

地圖規則周圍沒有引號。

試試這個

chrome_options.add_argument('--host-rules="MAP * localhost"')
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')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM