MacOS系统下selenium之火狐浏览器驱动firefoxdriver安装

MacOS系统selenium3.141.0之火狐浏览器驱动firefoxdriver安装

fireFoxdriver.exe各版本下载链接](http://ftp.mozilla.org/pub/firefox/releases/)
(http://ftp.mozilla.org/pub/firefox/releases/)
安装说明(参考)
http://yun.itheima.com/jishu/76.html
https://blog.youkuaiyun.com/aehawking0110/article/details/102402793

1、下载fireFoxdriver.exe

查询selenium版本号
pip show selenium
在这里插入图片描述

2、下载火狐浏览器

(从网上找到selenium&火狐浏览器&geckodriver三者对应的版本,否则可能出错)
本机是如下版本
在这里插入图片描述
https://ftp.mozilla.org/pub/firefox/releases/

3、下载对应的geckodriver

https://github.com/mozilla/geckodriver/releases
在这里插入图片描述

4、把解压后的 geckodriver,放在 /usr/local/bin/ 路径下

(或者直接放入爬虫文档中,详情见6使用方法)
在这里插入图片描述

5、修改 path 环境变量设置

在这里插入图片描述
打开环境变量文件

sudo vi ~/.bash_profile

添加配置项

export PATH=$PATH:/usr/local/bin/geckodriver

重启生效配置项

source ~/.bash_profile

检查配置项

echo $PATH

在这里插入图片描述
6、使用方法:
方法1:将geckodriver.exe在本机存放地址写入executable_path中
browser=Firefox(executable_path=’/usr/local/bin/geckodriver’,options=option)
蓝色为geckodriver.exe的位置
方法2:直接将geckodriver.exe放到爬虫.py文件同级中
browser = Firefox(executable_path=‘geckodriver’,options=option)

验证方法

from selenium.webdriver import Firefox
from selenium.webdriver import FirefoxOptions
import time,re
option = FirefoxOptions()
option.add_argument("--headless")  # 隐藏浏览器
browser=Firefox(executable_path='/usr/local/bin/geckodriver',options=option)
url = "http://www.nhc.gov.cn/xcs/yqtb/list_gzbd.shtml"
browser.get(url)
time.sleep(5)
print(browser)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值