python selenium无法打开Firefox浏览器

时间:2015-01-31 15:12:02

标签: 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\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()

4 个答案:

答案 0 :(得分:0)

您需要提供路径:

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

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

答案 1 :(得分:0)

你的硒版本很老了。

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

答案 2 :(得分:0)

请记住在您的系统路径中引入selenium和firefox,然后您可以使用此代码,有时候依赖于您需要安装gekodriver的Firefox版本

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")

答案 3 :(得分:-1)

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

from selenium import webdriver

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

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