记录一下Unbuntu安装selenium + Python3 + chromedrive环境遇到的困难
Chromedrive
从http://chromedriver.storage.googleapis.com/index.html选择对应版本进行安装。 安装到Download目录之后,解压.复制到bin目录下
sudo cp -r chromedrive /usr/bin
Python3
Unbuntu 自带Python3 版本,可以查询Python 版本
python3 --version
Selenium
sudo pip install selenium
提示已经安装了,估计unbuntu已经自带了.
python3
>>import selenium
>>help(selenium)
编辑了一个Py文件进行测试
# -*- coding: utf-8 -*-
from selenium import webdriver
help(selenium)
driver = webdriver.Firefox()
driver.get('www.baidu.com')
driver.quit()
发现类似下面错误 Traceback (most recent call last): File “/home/yanner/seleniumtest/sousuo.py”, line 2, in browser = webdriver.Firefox() File “/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py”, line 164, in init self.service.start() File “/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py”, line 83, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH.
于是参考网上解决办法: ubuntu系统,使用selenium3.X版本的,火狐浏览器需要下载geckodriver:
https://github.com/mozilla/geckodriver/releases
下载后直接解压,将解压后的文件geckodriver放入/usr/local/bin目录下(该目录是存放执行文件的)
打开终端输入以下命令:
su root (如出现su认证失败请点击看上一篇文章)
然后进入文件geckodriver存放的目录,将该文件复制到/usr/local/bin目录下
root@yanner-VirtualBox:/home/yanner# cd ruanjian root@yanner-VirtualBox:/home/yanner/ruanjian# cp geckodriver /usr/local/bin/ root@yanner-VirtualBox:/home/yanner/ruanjian# 再次运行:
from selenium import webdriver browser = webdriver.Firefox()
不再提示:‘geckodriver’ executable needs to be in PATH.
成功解决,环境配置完毕.
|