对于Linux系统,运行Selnium脚本报错如下
Traceback (most recent call last):
File "./obp_pb_get_csv.py", line 73, in <module>
browser = webdriver.Chrome('/usr/bin/chromium') # Get local session of chrome
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 46, in __init__
self.service.start()
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/service.py", line 64, in start
raise WebDriverException("Can not connect to the ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'Can not connect to the ChromeDriver'
解决方式:
1.确认Chrome浏览器是否已安装 ,命令: chromium-browser -version
2.如果没有安装,使用以下命令进行安装:
sudo apt-get install chromium-browser
3.获取ChromeDriver,访问如下链接 http://chromedriver.storage.googleapis.com/index.html
4.解压Chromdriver.zip
5.将文件移动到该路径/usr/bin,命令: sudo mv chromedriver /usr/bin
6.切换到/usr/bin目录,命令: cd /usr/bin
7.使得其变成可执行文件,命令 :sudo chmod a+x chromedriver
8.执行以下代码测试:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.google.com")
print driver.page_source.encode('utf-8')
driver.quit()
display.stop()