我知道已经有人问过类似的问题,但即使在谷歌上搜索了几个小时,进行了研究和比较,我还是无法找出问题所在。我的最终目标是使用selenium对Python进行一些web抓取,但是现在我甚至无法启动webdriver。这是到目前为止我得到的代码和错误消息:
$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyvirtualdisplay import Display
>>> from selenium import webdriver
>>>
>>> display = Display(visible=0, size=(1024, 768))
>>> display.start()
<Display cmd_param=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '1024x768x24', ':1069'] cmd=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '1024x768x24', ':1069'] oserror=None return_code=None stdout="None" stderr="None" timeout_happened=False>
>>> d = webdriver.Chrome()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 96, in start
self.assert_process_still_running()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1
chromedriver版本为2.30,位于:
^{pr2}$因为它在/usr/local/bin
中,所以我不需要像d = webdriver.Chrome("/path/to/chromedriver")
中那样在实例化webdriver时指定路径。在
在我能够运行以上代码之前,我安装了googlechrome浏览器、xvfb、pyvirtualdisplay和selenium。我使用的命令用于:
sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
sudo apt-get install -f
sudo apt-get install xvfb
wget -N http://chromedriver.storage.googleapis.com/2.30/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/local/bin
sudo pip install pyvirtualdisplay selenium
所以,我有所有软件的最新版本。如果能帮我解决问题,我将不胜感激。事先非常感谢。在
当我使用selenium和PhantomJs驱动程序通过nohup(也提到了there)运行进程时,遇到了同样的问题,我需要在虚拟机中捕获输出,而不是依赖于打开的会话。在
我开始使用tmux来实现这个目的,它不会像nohup那样阻塞信号,问题也就消失了。在
相关问题 更多 >
编程相关推荐