【发布时间】:2018-12-19 04:59:03
【问题描述】:
尝试将 uBlock 添加到浏览器会话,但它不起作用。
import selenium
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.options import Options as options
def establish_browser(type, hide):
browser = ''
if type == 'firefox':
ops = options()
ops.add_argument("--headless") if hide is True else ops.add_argument("--head")
profile = selenium.webdriver.FirefoxProfile()
profile.add_extension(extension='uBlock0@raymondhill.net.xpi')
browser = selenium.webdriver.Firefox(firefox_profile=profile, executable_path='geckodriver.exe', options=ops, firefox_binary=FirefoxBinary('C:/Program Files/Mozilla Firefox/firefox.exe'))
return browser
browser = establish_browser('firefox', False)
应如何更改以使 uBlock 正常工作?
更新
chrome 版本似乎正在运行……
if type == 'chrome':
from selenium.webdriver.chrome.options import Options as options
ops = options()
ops.add_argument("--headless") if hide is True else ops.add_argument("--head")
ops.add_extension("ublock.crx")
browser = selenium.webdriver.Chrome(executable_path='chromedriver.exe', options=ops, desired_capabilities={'binary_location': 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'})
Firefox 折旧了吗?
【问题讨论】:
-
您是否在 geckodriver 问题跟踪器上创建了一个关于此的问题?
-
我可能会这样做,我明天会研究它
标签: python selenium selenium-webdriver selenium-firefoxdriver