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
32 位:tar -xvf phantomjs-2.1.1-linux-i686.tar.bz2
64 位:tar -xvf phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo mv phantomjs-2.1.1-linux-x86_64.tar.bz2 /usr/local/src/phantomjs
sudo apt-get install build-essential chrpath libssl-dev libxft-dev libfreetype6-dev libfreetype6 libfontconfig1-dev libfontconfig1 -y
sudo ln -sf /usr/local/src/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
在控制台输入phantomjs -v
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 #查看版本
查看相应的浏览器版本
https://chromedriver.storage.googleapis.com/index.html
115以及以后最新版的驱动版本下载地址如下:https://registry.npmmirror.com/binary.html?path=chrome-for-testing/
选择对应的浏览器版本,下载对应的chromedriver
解压,上传到服务器的/usr/bin目录下
chmod 777 chromedriver
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()