selenium firefox chrome

Firefox版本:58.0.2 (64-bit)
Ubuntu系统

firefox安装方式
(1)命令行安装,sudo apt-get install firefox
(2)下载安装包,解压安装

selenium在调用Firefox时需要geckodriver , 下载后添加到Firefox安装目录/usr/lib/firefox/, 同时添加Firefox安装目录到系统环境变量Path,vim ~/.bashrc ,在文件最末尾添加

#firefox
export PATH=/usr/lib/firefox/:$PATH

查看$PATH包含哪些echo $PATH

selenium更新,selenium-3.9.0

sudo pip install -U selenium

firefox驱动下载网址,https://github.com/SeleniumHQ/selenium/blob/master/py/docs/source/index.rst
最简单的demo

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.baidu.com")

虚拟显示器pyvirtualdisplay,另外,还有Headless Chrome,以及Headless firefox了。https://developers.google.cn/web/updates/2017/04/headless-chrome,Headless Chrome。https://developer.mozilla.org/en-US/Firefox/Headless_mode,Headless firefox。

浏览器清除缓存
python + selenium + chrome 如何清理浏览器缓存
http://blog.csdn.net/zwq912318834/article/details/79215400

chrome

chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory" : "/some/path"}
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "path/to/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)

https://sites.google.com/a/chromium.org/chromedriver/capabilities

你可能感兴趣的:(Crawler)