pip3 install selenium
pip3 安裝參考javascript
yum install chromedriver.x86_64html
cat << EOF > /etc/yum.repos.d/google-chrome.repo [google-chrome] name=google-chrome baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64 enabled=1 gpgcheck=1 gpgkey=https://dl.google.com/linux/linux_signing_key.pub EOF
from selenium import webdriver driver = webdriver.Chrome() driver.get('http://www.baidu.com/') print( driver.title ) driver.quit()
若是遇到錯誤"unknown error: DevToolsActivePort file doesn't exist " 使用如下配置java
from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_argument('--headless') driver = webdriver.Chrome(chrome_options=chrome_options) driver.get('http://www.baidu.com/') print( driver.title ) driver.quit()
1.下載地址:http://phantomjs.org/download.htmlpython
2.文件名:phantomjs-2.1.1-linux-x86_64.tar.bz2linux
# 下載好後進行解壓(因爲是bz2格式,要先進行bzip2解壓成tar格式,再使用tar解壓)
yum -y install bzip2.x86_64
bzip2 -d phantomjs-2.1.1-linux-x86_64.tar.bz2web
# 再使用tar進行解壓到/usr/local/目錄下邊
tar xvf phantomjs-2.1.1-linux-x86_64.tar -C /usr/local/chrome
# 安裝依賴軟件
yum -y install wget fontconfigless
# 重命名(方便之後使用phantomjs命令)
mv /usr/local/phantomjs-2.1.1-linux-x86_64/ /usr/local/phantomjs測試
# 最後一步就是創建軟鏈接了(在/usr/bin/目錄下生產一個phantomjs的軟鏈接,/usr/bin/是啥目錄應該清楚,不清楚使用 echo $PATH查看)
ln -s /usr/local/phantomjs/bin/phantomjs /usr/bin/
複製代碼
到這一步就安裝成功了,接下來測試一下(通過上面創建的軟鏈接,你就能夠使用了,並且是想使用命令同樣的進行使用哦!):ui
[root@localhost ~]# phantomjs
phantomjs>
phantomjs> phantom.exit();