python - 如何始终允许在 Gecko 驱动程序或 Python Selenium 上的网站中定位
问题描述
嗨,我想始终允许位置或特定网站,但我无法解决我的问题。
现在我打开页面信息并手动设置,但我想以编程方式进行。
fp = webdriver.FirefoxProfile('Path'
'-1602622171076')
fp.set_preference("browser.privatebrowsing.autostart", True)
driver = webdriver.Firefox(firefox_profile=fp, executable_path='Path')
driver.get(url)
解决方案
1.对于铬:
from selenium.webdriver.chrome.options import Options
# to accept all the notifications
opt = Options()
opt.add_argument("--disable-infobars")
opt.add_argument("start-maximized")
opt.add_argument("--disable-extensions")
opt.add_experimental_option("prefs", { \
"profile.default_content_setting_values.media_stream_mic": 1,
"profile.default_content_setting_values.media_stream_camera": 1,
"profile.default_content_setting_values.geolocation": 1,
"profile.default_content_setting_values.notifications": 1
})
它是接受所有通知的代码
1 表示同意
0 表示禁用
如果你想禁用任何只是用 0 替换 1
- 对于 Mozilla 火狐:
from selenium.webdriver.firefox.options import Options
options = Options()
options.set_preference("dom.webnotifications.enabled", True)
driver = webdriver.Firefox(firefox_options=options)
推荐阅读
- javascript - 计时器不会随着我的 if 语句停止,是我放错了地方吗?
- sql - 左连接产生带有值的行和另一个带有 NULL 的行
- html - 将内容(数据)从一个 DIV 移动到另一个 DIV
- android - 在 Fragment 中使用 viewPager 时在 Fragment 中崩溃
- vba - adodb连接在虚拟机上不起作用
- javascript - 如何模拟 jQuery .done() 使其与 Jest 一起正确执行?
- javascript - 有人可以解释这段代码的作用吗?
- c# - .net core AsyncLocal 失去了 System.Reactive 的上下文
- c# - 如何在 LINQ 查询中应用多个可选过滤器
- java - 如何使用 Powermock easyMock 测试静态 void 函数?