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 在vps上运行Selenium_Python_Selenium_Vps - Fatal编程技术网

Python 在vps上运行Selenium

Python 在vps上运行Selenium,python,selenium,vps,Python,Selenium,Vps,我有一个简单的python脚本,可以在本地机器上正常工作。但如果我尝试在我的vps上运行它,我会得到一个错误: Traceback (most recent call last): File "test.py", line 15, in <module> browser = webdriver.Firefox(profile) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox

我有一个简单的python脚本,可以在本地机器上正常工作。但如果我尝试在我的vps上运行它,我会得到一个错误:

Traceback (most recent call last):
  File "test.py", line 15, in <module>
    browser = webdriver.Firefox(profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 77, in __init__
    self.binary, timeout),
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 49, in __init__
    self.binary.launch_browser(self.profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable()
  File "/usr/local/lib/python2.7/dist-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.

由于vps没有GUI,这是导致错误的原因吗

您必须使用
xvfb
包才能正确运行webdriver

usr/bin/xvfb-run /usr/bin/python myfile.py

查看更多细节

@RajarshiDas:所以,这个问题应该是个骗局。为什么不投票结束而不发表评论?出于好奇,为什么你认为这个问题值得回答而不值得投票?很好的提示,谢谢:)
usr/bin/xvfb-run /usr/bin/python myfile.py