使用 python 禁用 selenium-chromedriver 中的地理定位

2024-03-07

当我访问 https 网站时,想要使用 Chromedriver 禁用 Chrome 中的自动地理定位。

Tryed:

from selenium.webdriver.chrome.options import Options
chromeOptions = webdriver.ChromeOptions()
prefs = {"profile.default_content_settings.geolocation" : "2"}
chromeOptions.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)

And:

from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=chrome_options)

两者都不起作用,因为在使用 chromedriver 创建的每个新 chrome 窗口上都启用了地理定位。


您的首选密钥不正确,下面的代码对我有用

options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.geolocation" :2}
options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=options)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 python 禁用 selenium-chromedriver 中的地理定位 的相关文章

随机推荐