Loading ublock with custom filter in Chromium Selenium and Python3

Viewed 576

I'm developing a scraping script to collect some data which is behind an authwall, I've got a custom filter in ublock which gets me past the authwall however when i load chromium with ublock using Selenium it doesn't have the filters. I'm using Linux if that helps.

I've tried getting it to pause before getting the information to allow me to check the filters in place and it is blank.

Here is a portion of the code

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


    chrome_option_settings = Options()
    chrome_option_settings.add_argument('--window-size=1920x1080')
    extension_path = r'/home/user/.config/chromium/Default/Extensions/cjpalhdlnbpafiamejdnhcphjbkeiagm/1.20.0_0'
    chrome_option_settings.add_argument('load-extension='+extension_path)


    chrome_driver = "/usr/bin/chromedriver"
    driver = webdriver.Chrome(chrome_options=chrome_option_settings, executable_path=chrome_driver)
    driver.get(url)

I've also tried to load the Chrome profile using either however neither help.

    chrome_options.add_argument("user-data-dir=/home/user/.config/chromium/Default")

or

    chrome_options.add_argument("--profile-directory=/home/user/.config/chromium/Default")

Any help would be greatly appreciated

1 Answers

You could try using Options() and invoking add_extension with the path to ublock, hope this helps

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

chrome_options = Options()
executable_path = "path_to_webdriver"
extension_path = r'/home/user/.config/chromium/Default/Extensions/cjpalhdlnbpafiamejdnhcphjbkeiagm/1.20.0_0'

chrome_options.add_extension(extension_path)

driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options) 
Related