ubuntu下安装PhantomJS

1.下载

32位:wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-i686.tar.bz2

64位:wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2

2.解压

32 位:tar -xvf phantomjs-2.1.1-linux-i686.tar.bz2

64 位:tar -xvf phantomjs-2.1.1-linux-x86_64.tar.bz2

3.移动文件

sudo mv phantomjs-2.1.1-linux-x86_64.tar.bz2 /usr/local/src/phantomjs

4.安装相关依赖

sudo apt-get install build-essential chrpath libssl-dev libxft-dev libfreetype6-dev libfreetype6 libfontconfig1-dev libfontconfig1 -y

5.设置环境变量

sudo ln -sf /usr/local/src/phantomjs/bin/phantomjs /usr/local/bin/phantomjs

6.验证安装

在控制台输入phantomjs -v

ubuntu下安装chrome

1.下载

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 #Might show "errors", fixed by next line

sudo apt-get install -f

google-chrome --version #查看版本

查看相应的浏览器版本

2.下载chromedriver

https://chromedriver.storage.googleapis.com/index.html

115以及以后最新版的驱动版本下载地址如下:https://registry.npmmirror.com/binary.html?path=chrome-for-testing/

选择对应的浏览器版本,下载对应的chromedriver

解压,上传到服务器的/usr/bin目录下

3.赋予权限

chmod 777 chromedriver

4.测试

from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_argument('headless')
driver = webdriver.Chrome(executable_path='chromedriver', chrome_options=option)
driver.get("http://www.baidu.com")
page_src = driver.page_source
print(page_src)
driver.quit()