linux安装selenium+chrome+phantomjs

1. 安装 selenium

pip3 install selenium
pip3 安装参考javascript

2. 安装 ChromeDriver

yum install chromedriver.x86_64html

3. 安装 Chrome

  1. 配置源,终端复制执行下面的代码
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 
  1. 安装 chrome
    yum install google-chrome-stable

4.测试

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()

 phantomjs 


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();

相关文章
相关标签/搜索