Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.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

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
python selenium无法打开Firefox浏览器_Python_Selenium - Fatal编程技术网

python selenium无法打开Firefox浏览器

python selenium无法打开Firefox浏览器,python,selenium,Python,Selenium,我正在使用Python和selenium。当我尝试使用python selenium打开Firefox时,出现以下错误 >>> driver = webdriver.Firefox() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\selenium-2.39.0-py2.7.egg

我正在使用Python和selenium。当我尝试使用python selenium打开Firefox时,出现以下错误

>>> driver = webdriver.Firefox()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 59, in __init__
    self.binary, timeout),
  File "C:\Python27\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
    self.binary.launch_browser(self.profile)
  File "C:\Python27\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 61, in launch_browser
    self._wait_until_connectable()
  File "C:\Python27\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 105, in _wait_until_connectable
    self.profile.path, self._get_firefox_output()))
selenium.common.exceptions.WebDriverException: Message: 'Can\'t load the profile. Profile Dir: c:\\users\\workshop\\appdata\\local\\temp\\tmpzcofay Firefox output: 1422716384881\taddons.manager\tDEBUG
\tLoaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]\r\n1422716384882\taddons.manager\tDEBUG\tLoaded provider scope for resource://gre/modules/LightweightThemeMan
ager.jsm: ["LightweightThemeManager"]\r\n1422716384884\taddons.xpi\tDEBUG\tstartup\r\n1422716384886\taddons.xpi\tINFO\tMapping fxdriver@googlecode.com to c:\\users\\workshop\\appdata\\local\\temp\\tmp
zcofay\\extensions\\fxdriver@googlecode.com\r\n1422716384887\taddons.xpi\tINFO\tMapping {F17C1572-C9EC-4e5c-A542-D05CBB5C5A08} to C:\\Program Files (x86)\\DAP\\DAPFireFox\r\n1422716384887\taddons.xpi\
tINFO\tMapping {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} to C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi\r\n1422716384888\taddons.xpi\tINFO\tM
apping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}\r\n1422716384888\taddons.xpi\tDEBUG\tSkipping una
vailable install location app-system-share\r\n1422716384888\taddons.xpi\tDEBUG\tSkipping unavailable install location app-system-local\r\n1422716384889\taddons.xpi\tINFO\tMapping {74c841e3-b59f-479e-8
d7a-e26a942a87c8} to C:\\Program Files (x86)\\WinZip Courier\\FFExt\r\n1422716384889\taddons.xpi\tINFO\tMapping {01A8CA0A-4C96-465b-A49B-65C46FAD54F9} to C:\\Program Files (x86)\\Adobe\\Adobe Contribu
te CS5.1\\Plugins\\FirefoxPlugin\\{01A8CA0A-4C96-465b-A49B-65C46FAD54F9}\r\n1422716384889\taddons.xpi\tINFO\tMapping web2pdfextension@web2pdf.adobedotcom to C:\\Program Files (x86)\\Adobe\\Acrobat 10.
0\\Acrobat\\Browser\\WCFirefoxExtn\r\n1422716384889\taddons.xpi\tINFO\tMapping daplinkchecker@speedbit.com to C:\\Program Files (x86)\\DAP\\daplinkchecker\r\n1422716384890\taddons.xpi\tINFO\tMapping s
earchpredict@speedbit.com to C:\\Program Files (x86)\\SearchPredict\\PRFireFox\r\n1422716384890\taddons.xpi\tINFO\tMapping {0329E7D6-6F54-462D-93F6-F5C3118BADF2} to C:\\Program Files (x86)\\SPEEDbit V
ideo Downloader\\SPFireFox\r\n1422716384890\taddons.xpi\tINFO\tMapping adapter@gingersoftware.com to C:\\Program Files (x86)\\Ginger\\Mozilla\\adapter@gingersoftware.com\r\n1422716384891\taddons.xpi\t
DEBUG\tcheckForChanges\r\n'
>>> driver = webdriver.Firefox()
>driver=webdriver.Firefox()
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“C:\Python27\lib\site packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\firefox\webdriver.py”,第59行,在\uuu init中__
self.binary,超时),
文件“C:\Python27\lib\site packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\firefox\extension\u connection.py”,第47行,在\uu init中__
self.binary.launch_浏览器(self.profile)
启动浏览器中的文件“C:\Python27\lib\site packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\firefox\firefox\u binary.py”,第61行
self.\u等待\u直到\u可连接()
文件“C:\Python27\lib\site packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\firefox\firefox\u binary.py”,第105行,在可连接之前等待
self.profile.path,self.\u get\u firefox\u output())
selenium.common.exceptions.WebDriverException:消息:“无法加载配置文件。”。配置文件目录:c:\\users\\workshop\\appdata\\local\\temp\\tmpzcofay Firefox输出:1422716384881\taddons.manager\tDEBUG
\t加载的提供程序作用域resource://gre/modules/addons/XPIProvider.jsm: [“XPIProvider”]\r\n1422716384882\taddons.manager\tDEBUG\t加载的提供程序范围resource://gre/modules/LightweightThemeMan
ager.jsm:[“LightweightTheManager”]\r\n1422716384884\taddons.xpi\tDEBUG\tstartup\r\n1422716384886\taddons.xpi\tINFO\t映射fxdriver@googlecode.com到c:\\users\\workshop\\appdata\\local\\temp\\tmp
zcofay\\extensions\\fxdriver@googlecode.com\r\n1422716384887\taddons.xpi\tINFO\t将{f17c157-C9EC-4e5c-A542-d05cb5c5a08}映射到C:\\Program Files(x86)\\DAP\\DAPFireFox\r\n1422716384887\taddons.xpi\
tINFO\t将{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}映射到C:\\Program Files(x86)\\Mozilla Firefox\\browser\\extensions\\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi\r\n1422716384888\taddons.xpi\tINFO\tM
将{972ce4c6-7e08-4474-a285-3208198ce6fd}应用于C:\\Program Files(x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}\r\n1422716384888\taddons.xpi\tDEBUG\tskiuna
可用安装位置应用程序系统共享\r\n1422716384888\tADONS.xpi\tDEBUG\tSkiping不可用安装位置应用程序系统本地\r\n1422716384889\tADONS.xpi\tINFO\tMapping{74c841e3-b59f-479e-8
d7a-e26a942a87c8}到C:\\Program Files(x86)\\WinZip Courier\\FFExt\r\n1422716384889\taddons.xpi\tINFO\t映射{01A8CA0A-4C96-465b-A49B-65C46FAD54F9}到C:\\Program Files(x86)\\Adobe\\Adobe Contribu
te CS5.1\\Plugins\\FirefoxPlugin\{01A8CA0A-4C96-465b-A49B-65C46FAD54F9}\r\n1422716384889\taddons.xpi\tINFO\t映射web2pdfextension@web2pdf.adobedotcom到C:\\ProgramFiles(x86)\\Adobe\\Acrobat 10。
0\\Acrobat\\Browser\\WCFirefoxExtn\r\n1422716384889\taddons.xpi\tINFO\t映射daplinkchecker@speedbit.com到C:\\Program Files(x86)\\DAP\\daplinkchecker\r\n1422716384890\taddons.xpi\tINFO\t映射
earchpredict@speedbit.com到C:\\Program Files(x86)\\SearchPredict\\PRFireFox\r\n1422716384890\taddons.xpi\tINFO\t将{0329E7D6-6F54-462D-93F6-F5C3118BADF2}映射到C:\\Program Files(x86)\\SPEEDbit V
ideo Downloader\\SPFireFox\r\n1422716384890\taddons.xpi\tINFO\t映射adapter@gingersoftware.com到C:\\ProgramFiles(x86)\\Ginger\\Mozilla\\adapter@gingersoftware.com\r\n1422716384891\taddons.xpi\t
调试\t检查更改\r\n'
>>>driver=webdriver.Firefox()

您需要提供路径:

from selenium import webdriver
ff_profile = webdriver.FirefoxProfile()
browser = webdriver.Firefox(firefox_profile=ff_profile)

请检查它是否适用于您(它适用于我,但如果没有路径,我会得到与您相同的错误)。

您需要导入正确的模块。别忘了给他们打电话。请查看下面的示例:

from selenium import webdriver

browser = webdriver.Firefox()
browser.get("Insert URL here")

运行它,它应该会工作。如果没有,请告诉我。

您的selenium版本已经很旧了


您必须安装最新版本2.53,它应该可以解决您的问题。

记住在您的系统路径中引入selenium和firefox,然后您可以使用此代码,有时根据您拥有的firefox版本,您还需要安装gekodriver

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

driver = webdriver.Firefox()
driver.get("YOUR_URL") 
如果没有在系统路径中引入它们,则可以使用以下其他代码:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary("C:\Program Files (x86)\Mozilla Firefox\Firefox.exe")#path of Firefox.exe
driver = webdriver.Firefox(firefox_binary=binary)
driver.get("YOUR_URL")