python环境配置selenium与IE、Chrome、Firefox、PhantomJS
安装、升级selenium
pip install -U selenium
下载对应平台最新版的browser driver
chrome:
http://chromedriver.storage.googleapis.com/index.html
ie:
http://selenium-release.storage.googleapis.com/index.html
firefox:
https://github.com/mozilla/geckodriver/releases
将需要的browser driver所在目录添加到环境变量path,如
d:\bin\chromedriver.exe
d:\bin\geckodriver.exe
d:\bin\IEDriverServer.exe
测试
# coding: utf-8
from selenium import webdriver
driver = webdriver.Chrome()
# driver = webdriver.Firefox()
# driver = webdriver.Ie()
driver.get("http://www.python.org")
找不到浏览器(portable版本等情况)
binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
PhantomJS
将phantomjs.exe所在目录添加到环境变量path,然后测试:
driver = webdriver.PhantomJS()
driver.get_screenshot_as_file('show.png')
driver.quit()
本文原创发表于http://www.cnblogs.com/qijj,转载请保留此声明。