I want to use selenium to scrape off some website. I can't access the website via my own internet connection, so I need to use browsec Mozilla add-on for that. I am unable to launch Firefox with selenium with the add-on enabled.
Below are the steps I did:
import selenium
from selenium import webdriver
url = "http://url"
profile = webdriver.FirefoxProfile()
profile.add_extension('browsec@browsec.com.xpi')
#profile.add_extension("C:\Users\urs\AppData\Roaming\Mozilla\Firefox\Profiles\abc.default\extensions\browsec@browsec.com.xpi")
driver = webdriver.Firefox(firefox_profile=profile)
if __name__ == "__main__":
driver.get(url)
driver.wait(5)
driver.quit()
I added the extension in the same directory where my script is kept using the following
profile.add_extension('browsec@browsec.com.xpi')
It through me an error:
Traceback (most recent call last): File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 346, in _addon_details with open(os.path.join(addon_path, 'install.rdf'), 'r') as f: FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Usr\AppD ata\Local\Temp\tmp0hny31u3.browsec@browsec.com.xpi\install.rdf'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "test.py", line 7, in profile.add_extension("browsec@browsec.com.xpi") File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 95, in add_extension self._install_extension(extension) File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 274, in _install_extension addon_details = self._addon_details(addon) File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 351, in _addon_details raise AddonFormatError(str(e), sys.exc_info()[2]) selenium.webdriver.firefox.firefox_profile.AddonFormatError: ("[Errno 2] No such file or directory: 'C:\\Users\\Usr\\AppData\\Local\\Temp\\tmp0hn y31u3.browsec@browsec.com.xpi\\install.rdf'", )
I also tried giving the path to the extension:
profile.add_extension("C:\Users\urs\AppData\Roaming\Mozilla\Firefox\Profiles\abc.default\extensions\browsec@browsec.com.xpi")
And I ran into this error:
profile.add_extension("C:\Users\Hassan\AppData\Roaming\Mozilla\Firefox\Profi les\n5jwlj9l.default\extensions\browsec@browsec.com.xpi") ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in positio n 2-3: truncated \UXXXXXXXX escape
Formatting the path string like below doesn't help either.
profile.add_extension(r"C:\Users\urs\AppData\Roaming\Mozilla\Firefox\Profiles\abc.default\extensions\browsec@browsec.com.xpi")
I get the following:
Traceback (most recent call last): File "test.py", line 7, in profile.add_extension(r"C:\Users\Hassan\AppData\Roaming\Mozilla\Firefox\Prof iles\n5jwlj9l.default\extensions\browsec@browsec.com.xpi") File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 95, in add_extension self._install_extension(extension) File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 274, in _install_extension addon_details = self._addon_details(addon) File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 351, in _addon_details raise AddonFormatError(str(e), sys.exc_info()[2]) selenium.webdriver.firefox.firefox_profile.AddonFormatError: ("[Errno 2] No such file or directory: 'C:\\Users\\usr\\AppData\\Local\\Temp\\tmp1he 0fym_.browsec@browsec.com.xpi\\install.rdf'", )
How do I configure selenium to run firefox with browsec enabled by default?