Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过selenium和python在firefox中加载扩展_Python_Selenium_Headless_Selenium Firefoxdriver - Fatal编程技术网

通过selenium和python在firefox中加载扩展

通过selenium和python在firefox中加载扩展,python,selenium,headless,selenium-firefoxdriver,Python,Selenium,Headless,Selenium Firefoxdriver,我正在尝试用python中的selenium浏览器将firefox插件加载到headless firefox中 from selenium import webdriver import time geckodriver = 'C:\\Gecko\\geckodriver.exe' options = webdriver.FirefoxOptions() options.add_argument('-headless') profile = webdriver.FirefoxProfile

我正在尝试用python中的selenium浏览器将firefox插件加载到headless 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\u profile.py”,第351行,位于\u addon\u详细信息中 raise AddonFormatError(str(e),sys.exc_info()[2])

AddonFormatError:(“[Errno 2]没有这样的文件或目录:'C:\\Users\\AppData\\Local\\Temp\\tmp6cn69jiy。”。uBlock0@raymondhill.net.xpi\\安装.rdf',)

你有什么想法吗?我一直在网站上的其他帖子中寻找,但没有找到任何适合该代码的东西


谢谢大家!

尝试使用Firefox开发者版而不是标准Firefox。这在C#中对我起了作用。希望这个解决方案能对您有所帮助。
另外,正如我在你的代码中看到的那样,你可以在Firefox中使用一个特定的配置文件,因此最简单的方法是手动将扩展添加到你的配置文件中,这样你就不必通过编程来完成它,它应该可以在一个更新的Firefox版本中工作。更新Firefox并重试

是否使用最新版本?据我记忆所及,这是firefox驱动程序中的一个bug,他们在我使用firefox Quantum 62.0.2(64位)之前修复了它。我刚刚安装了firefox的最新更新,现在可以使用了。谢谢你,基里尔!