将adblock添加到Chrome python selenium webdrive

时间:2016-04-29 15:42:55

标签: python selenium selenium-webdriver google-chrome-extension adblock

我尝试使用以下代码将adblock添加到selenium:

chop =webdriver.ChromeOptions()
chop.add_extension('Adblock-Plus_v1.4.1.crx')
driver = webdriver.Chrome(chrome_options=chop)

我收到了这个错误:

'OSError: Path to the extension doesn't exist'

我该怎么办?

1 个答案:

答案 0 :(得分:1)

您需要提供完整路径:

from os import path

chop =webdriver.ChromeOptions()
chop.add_extension(path.abspath('Adblock-Plus_v1.4.1.crx'))
driver = webdriver.Chrome(chrome_options=chop)