【发布时间】:2019-03-07 14:49:51
【问题描述】:
我正在尝试在 python 中使用 selenium 浏览器将 firefox 插件加载到无头 firefox 中。
from selenium import webdriver
import time
geckodriver = 'C:\\Gecko\\geckodriver.exe'
options = webdriver.FirefoxOptions()
options.add_argument('-headless')
profile = webdriver.FirefoxProfile('C:/AppData/Roaming/Mozilla/Firefox/Profiles/am97bfb5.default-1538379314459')
profile.set_preference("network.http.use-cache", False)
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.socks", "127.0.0.1")
profile.set_preference("network.proxy.socks_port", 9150)
profile.set_preference("network.proxy.socks_version", 5)
profile.set_preference("javascript.enabled", True);
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.set_preference("general.useragent.override","Mozilla/5.0 (Linux; Android 6.0; HTC One M9 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36")
profile.exp="D:/test/XPI/uBlock0@raymondhill.net.xpi"
profile.add_extension(extension=profile.exp)
time.sleep(5)
browser = webdriver.Firefox(firefox_profile=profile,executable_path=geckodriver, firefox_options=options)
print (profile.path)
browser.get('https://intoli.com/blog/making-chrome-headless-undetectable/chrome-headless-test.html')
browser.save_screenshot('D:\\Test\\headless_firefox_test.png')
browser.quit()
但是运行代码后出现以下错误:
文件“C:\Anaconda\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py”,第 351 行,在 _addon_details 引发 AddonFormatError(str(e), sys.exc_info()[2])
AddonFormatError: ("[Errno 2] 没有这样的文件或目录:'C:\\Users\\AppData\\Local\\Temp\\tmp6cn69jiy.uBlock0@raymondhill.net.xpi\\install.rdf'" , )
你有什么想法吗?我一直在查看网站上的其他帖子,但没有找到任何适用于该代码的内容。
谢谢!
【问题讨论】:
-
您使用的是最新版本吗?据我记得这是Firefox驱动程序中的一个错误,他们前段时间修复了它
-
我使用的是 Firefox Quantum 62.0.2(64 位)
-
我刚刚安装了 Firefox 的最新更新,它现在可以运行了。谢谢基里尔!
标签: python selenium headless selenium-firefoxdriver