Selenium is a Web test application framework that can also be used as a crawler.
1. Installing the Selenium module
Pip Install-u Selenium
2. After installing the Selenium module, the corresponding browser driver is required.
A. Using PHANTOMJS
PHANTOMJS is a test browser with no interface
I'm using phantomjs-2.1.0-linux-x86_64 as long as I use the PHANTONJS in the Phantomjs-2.1.0-linux-x86_64 folder directly.
1 from Import Webdriver 2 3 Driver = Webdriver. Phantomjs ('/home/xx/xx/phantomjs-2.1.0-linux-x86_64/bin/phantomjs')## Inside is the address of Phantomjs 4 driver.get ("http://www.baidu.com")
This allows you to use driver to operate a browser with no interface.
PHANTOMJS:
B. Have a meeting with the Chrome browser installation configuration
First you need to install the Chrome browser and configure the relevant environment
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
sudo apt-get install unzip
wget -N http://chromedriver.storage.googleapis.com/2.26/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
安装相关selenimu
sudo apt-get install python-pip
pip install pyvirtualdisplay selenium
Test code
1 from Import Display 2 from Import Webdriver 3 Driver = webdriver. Chrome ()4 driver.get (' https://www.baidu.com/')5 Print Driver.title
RELATED Links: https://christopher.su/2015/selenium-chromedriver-ubuntu/
Python Selenium Development environment configuration