Open Firefox Webdriver with Adblock Plus Extension (Python)

I want to open Firefox using Python Webdriver and Adblock Plus extension.

Here's my code:

from selenium import webdriver

ffprofile = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_profile=ffprofile)


I am getting the following error:

Traceback (last call last): File "", line 6, in ffprofile.add_extension (extension = 'adblock.xpi') File "C: \ Python34 \ lib \ site-packages \ selenium \ webdriver \ firefox \ firefox_profile .py ", line 92, in add_extension self._install_extension (continued) File" C: \ Python34 \ lib \ site-packages \ selenium \ webdriver \ firefox \ ", line 269, in _install_extension addon_details = self._addon_details ( addon) File "C: \ Python34 \ lib \ site-packages \ selenium \ webdriver \ firefox \", line 341, in _addon_details manifest = () File "C: \ Python34 \ lib \ encodings \ cp1252 .py ", line 23, in decoding return codecs.charmap_decode (input, self.errors, decoding_table) [0] UnicodeDecodeError: codec 'charmap'cannot decode byte 0x8d at position 964: char map character to undefined

Other extensions work with this code without problems. Only the Adblock Plus extension ( ) doesn't work. Does anyone know a solution to this problem?


source to share

1 answer

This is because the adblock plus manifest file contains some Unicode characters.

There are two possible solutions:

  • Change code in selenium / webdriver / firefox /

    with open(os.path.join(addon_path, 'install.rdf'), 'r') as f:

to with open(os.path.join(addon_path, 'install.rdf'), 'r', encoding='utf8') as f:

  1. Download adblock_plus.xpi and remove the localization strings from the manifest (you can open the .xpi with any archive manager).

Also, this is a problem you can submit a ticket to the selenium bug tracker, so it is allowed in the selenium itself.



All Articles