码迷,mamicode.com
首页 > 系统相关 > 详细

Installing Selenium and ChromeDriver on Ubuntu

时间:2016-11-20 11:02:53      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:api   python   recently   top   dig   rect   imp   start   share   

I recently got Selenium, Google Chrome, and ChromeDriver installed and working on a DigitalOcean instance running 64-bit Ubuntu 14.04. Here’s how:

First, install Google Chrome for Debian/Ubuntu:

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

Now, let’s install xvfb so we can run Chrome headlessly:

sudo apt-get install xvfb

Install ChromeDriver:1

sudo apt-get install unzip

wget -N http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver

sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

Install some Python dependencies for Selenium:

sudo apt-get install python-pip

## (Optional) Create and enter a virtual environment:
# sudo apt-get install python-virtualenv
# virtualenv env
# source env/bin/activate

pip install pyvirtualdisplay selenium

Now, we can do stuff like this with Selenium in Python:

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Chrome()
driver.get(‘http://christopher.su‘)
print driver.title

Installing Selenium and ChromeDriver on Ubuntu

标签:api   python   recently   top   dig   rect   imp   start   share   

原文地址:http://www.cnblogs.com/imayi/p/ubuntu.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!