来自python selenium脚本的回溯错误(间歇性地工作)

时间:2016-06-22 18:48:16

标签: python linux selenium webdriver

我在Python中编写了一个selenium脚本,以自动发布到特定网站。我过去经营过它,它完美无缺。但是,我去运行脚本,现在突然收到下面的内容。 我相信这是模块加载的问题。另外有时firefox会打开,有时则不会。 Linux上的Mac。

脚本:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://losangeles.craigslist.org/')

错误:

/usr/bin/python2.7 /home/max/Desktop/CraigsList.py
Traceback (most recent call last):
  File "/home/max/Desktop/CraigsList.py", line 4, in <module>
    browser = webdriver.Firefox()
  File "/home/max/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 81, in __init__
    self.binary, timeout)
  File "/home/max/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/home/max/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/home/max/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
    raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.

1 个答案:

答案 0 :(得分:0)

  1. 尝试在控制台中运行FF,使用与运行python脚本相同的用户和路径
  2. 为webdriver设置log_file
  3. 也许最好使用PhantomJS驱动程序?