centos自带firefox,故不用另外下载浏览器
第一步下载geckodriver
wget https://github.com/mozilla/geckodriver/releases/download/v0.22.0/geckodriver-v0.22.0-linux64.tar.gz
各个版本的driver下载地址如下
https://github.com/mozilla/geckodriver/releases
解压
tar zxvf geckodriver-v0.22.0-linux64.tar.gz
转移
mv geckodriver /usr/local/bin
建立test.py文件测试
from selenium import webdriver
fireFoxOptions = webdriver.FirefoxOptions()
fireFoxOptions.set_headless()
brower = webdriver.Firefox(executable_path="/usr/local/bin/geckodriver",firefox_options=fireFoxOptions)
brower.get('http://www.baidu.com')
print(brower.page_source)
brower.close()
测试
python3 test.py
网友评论