Mac和Linux安装selenium+phantomjs+chromedriver

本文详细介绍了如何在Mac和Linux环境下安装Selenium、PhantomJS及ChromeDriver。包括PhantomJS的下载、环境变量配置、软连接创建及依赖安装等步骤,并提供了ChromeDriver的下载与安装方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

selenium安装

pip install selenium

一、phantomjs安装

1、Mac环境

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

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

将 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

https://npmmirror.com/

复制文件

$ 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 解决方法
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值