1

I am trying to load a version of firefox with adblock but i am getting an error.

profile = webdriver.FirefoxProfile()
adblockfile = '\Users\username\Downloads\adblock_plus-2.6.3-fx+an+sm+tb.xpi'
profile.add_extension (adblockfile)
profile.set_preference("extensions.adblockplus.currentVersion", "2.4")
browser = webdriver.Firefox(firefox_profile=profile)

error reads

the filename, directory name, or volume label syntax is incorrect: ' c:\\users\\username\\appdata\\local\\temp\\tmplt8yt3.download\x07dblock_plus-2.6.3-fx+an+sm+tb.xpi'

Not to sure what is going on and why the directory is messing up.

BubblewrapBeast
  • 1,507
  • 2
  • 15
  • 19

2 Answers2

0
adblockfile = '\Users\username\Downloads\adblock_plus-2.6.3-fx+an+sm+tb.xpi'

should be

adblockfile = r'\Users\username\Downloads\adblock_plus-2.6.3-fx+an+sm+tb.xpi'

otherwise, some backslashed characters (in this case, the '\a') get interpreted as escape sequences.

The r prefix before the quotation mark makes the string a raw string and tells Python to interpret the backslash as a literal backslash.


'\a' is the ASCII Bell (BEL) character, whereas r'\a' is a literal backslash followed by an a:

In [179]: '\adblock'
Out[179]: '\x07dblock'

In [180]: r'\adblock'
Out[180]: '\\adblock'
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
0

You are going to have further issues with loading the xpi since adblock will need to get its subscription list. Please see

Python Using Adblock with Selenium and Firefox Webdriver

Or you can save a profile that already has the subscription list downloaded

Community
  • 1
  • 1
sam-6174
  • 3,104
  • 1
  • 33
  • 34