我的目标是通过 Python 将 Adblock Plus 与 Selenium 一起使用。我已经能够让它加载扩展,但默认情况下它不包括默认过滤器“EasyList”。这是我到目前为止所拥有的:
from selenium import webdriver
from time import sleep
ffprofile = webdriver.FirefoxProfile()
adblockfile = '/Users/username/Downloads/adblock_plus-2.4-tb+fx+an+sm.xpi'
ffprofile.add_extension(adblockfile)
ffprofile.set_preference("extensions.adblockplus.currentVersion", "2.4")
browser = webdriver.Firefox(ffprofile)
while(True):
browser.get("www.cnn.com")
sleep(5)
大部分代码都是从http://selenium-python.readthedocs.org/en/latest/faq.html