当前位置: 首页 > 工具软件 > phan > 使用案例 >

Mac和Linux安装selenium+phantomjs+chromedriver

刘高驰
2023-12-01

selenium安装

pip install selenium

一、phantomjs安装

1、Mac环境

phantomjs下载:http://phantomjs.org/download.html

淘宝镜像:https://npm.taobao.org/mirrors/phantomjs

将 phantomjs bin 文件路径加入环境变量:

vim ~/.bash_profile

内容

 # phantomjs
 export PHANTOMJS_PATH=/Users/user/Applications/phantomjs-2.1.1-macosx
 export PATH=$PATH:${PHANTOMJS_PATH}/bin

执行

source  ~/.bash_profile

验证

phantomjs --version

如果程序报错可是试试加个软连

ln -s /Users/user/Applications/phantomjs-2.1.1-macosx/bin/phantomjs /usr/local/bin/phantomjs

2、Linux环境

淘宝镜像: https://npm.taobao.org/mirrors/phantomjs

# 下载
wget https://npm.taobao.org/mirrors/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2

# 解压
yum -y install bzip2
tar xvf phantomjs-2.1.1-linux-x86_64.tar.bz2

# 软连
ln -s phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs

检查

$ phantomjs --version

如果报错

phantomjs: error while loading shared libraries: libfontconfig.so.1: 
cannot open shared object file: No such file or directory

安装依赖

yum -y install fontconfig-devel

chromedriver下载:

谷歌下载(需要翻墙):https://sites.google.com/a/chromium.org/chromedriver/downloads

淘宝镜像:https://npm.taobao.org/mirrors/chromedriver

复制文件

$ cp chromedriver /usr/local/bin/

查看是否成功安装:

phantomjs --version
chromedriver --version

参考:

  1. mac 上安装selenium, phantomjs 和 chromedriver
  2. centos7下运行phantomjs报phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open
  3. tar (child): lbzip2: Cannot exec: No such file or directory 解决方法
 类似资料: