Skip to main content
 首页 » 编程设计

python selenium 不支持 firefox之消息 : Can't load the profile. Profile Dir

2025年04月02日13bhlsheji

为什么将 selenium 与 python 和 firefox 一起使用会发生这种情况? Selenium 不能扩展到一个简单的循环。为什么 firefox 不能缩放?随着时间的推移,它决定抛出一个错误并退出。

火狐浏览器 45.0 selenium.版本 '2.53.2'

from pyvirtualdisplay import Display 
display = Display(visible=0, size=(800, 600)) 
display.start() 
mylist = ['page1','page1',...,'pageN'] 
while True: 
   for data in mylist: 
 
        browser = webdriver.Firefox() 
        try: 
           myfunc(data) # Code that uses selenum to fetch pages 
        except: 
            pass 
        browser.quit() 
   time.sleep(60) 
 
 
 
No handlers could be found for logger "sentry.errors.serializer" 
Traceback (most recent call last): 
  File "platrieveerp.py", line 231, in <module> 
    browser = webdriver.Firefox() 
  File "/usr/local/lib/python2.7/dist-packages/selenium-2.53.2-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 103, in __init__ 
    self.binary, timeout) 
  File "/usr/local/lib/python2.7/dist-packages/selenium-2.53.2-py2.7.egg/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__ 
    self.binary.launch_browser(self.profile, timeout=timeout) 
  File "/usr/local/lib/python2.7/dist-packages/selenium-2.53.2-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser 
    self._wait_until_connectable(timeout=timeout) 
  File "/usr/local/lib/python2.7/dist-packages/selenium-2.53.2-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 106, in _wait_until_connectable 
    % (self.profile.path)) 
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /tmp/tmpOgsKOx If you specified a log_file in the FirefoxBinary constructor, check it for details. 

请您参考如下方法:

Selenium 在运行循环时没有失败,它在 webdriver.Firefox() 处失败。当脚本仍然无法识别打开的 Firefox 应用程序时,在第 231 行之后的特定时间连接超时时,会识别出该错误。

这只是在使用 headless 浏览器运行时 selenium 中的一个错误。要获得 selenium 的工作版本,请运行

sudo pip install -U selenium  

这应该是一个类似的问题: Selenium: FirefoxProfile exception Can't load the profile