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)