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 addon for that.
I am unable to launch firefox with selenium with the add-on enabled. Here is what I have tried:
import selenium
from selenium import webdriver
url = "http://url"
profile = webdriver.FirefoxProfile()
profile.add_extension('[email protected]')
#profile.add_extension("C:\Users\urs\AppData\Roaming\Mozilla\Firefox\Profiles\abc.default\extensions\[email protected]")
driver = webdriver.Firefox(firefox_profile=profile)
if __name__ == "__main__":
driver.get(url)
driver.wait(5)
driver.quit()
I have tried putting the extension in the same directory where my script is and using the following
profile.add_extension('[email protected]')
which gives me this error when I run:
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\[email protected]\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("[email protected]") 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 [email protected]\\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\[email protected]")
And I ran into this error:
profile.add_extension("C:\Users\Hassan\AppData\Roaming\Mozilla\Firefox\Profi les\n5jwlj9l.default\extensions\[email protected]") ^ 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\[email protected]")
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\[email protected]") 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 [email protected]\\install.rdf'", )
How do I configure selenium to run firefox with browsec enabled by default?