一、Python安装 Window系统下,python的安装很简单。访问python.org/download,下载最新版本,安装过程与其他windows软件类似。记得下载后设置path环境变量,然后Windows命令行就可以调用了:
二、Selenium安装 Python3.x安装后就默认就会有pip(pip.exe默认在python的Scripts路径下),使用pip安装selenium: pip install selenium
因我已安装selenium,不可重复安装。 可使用以下命令查看是否安装成功: pip show selenium
三、Firefox安装 因安装最新Firefox与selenium兼容有问题,所以安装旧版firefox47,记得在firefox安装插件firebug和firepath。(此外,记得关闭firefox的自动安装) Firefox旧版下载地址:http://ftp.mozilla.org/pub/firefox/releases/ 四、安装driver Selenium 3以前,使用firefox浏览器不需要额外的driver。但是Selenium 3.X 对firefox浏览器也需要安装相应的driver: Firefox浏览器需安装geckdriver,下载地址:https://github.com/mozilla/geckodriver/releases; 相应的,Chrome浏览器需要安装chromedriver,IE浏览器要安装IEdriver。 driver的路径可以直接放在python路径下,我这里把driver放在了python的Scripts路径下,同时把script路径加入环境变量。
五、运行一个简单的例子 使用python自带的IDLE工具,输入以下脚本: from selenium import webdriver # 导入webdriver包 import time driver.maximize_window() # 最大化浏览器 driver.get("https://www.baidu.com") # 通过get()方法,打开一个url站点 运行以上脚本,最终打开百度网址,证明运行成功。 PS,我的运行环境: Firefox浏览器版本:Firefox 47.0 Python:python v3.6.2 Selenium:3.7.0 Geckdriver:v0.15.0
六、浏览器驱动 各个浏览器驱动下载地址: geckodriver(Firefox):https://github.com/mozilla/geckodriver/releases Chromedriver(Chrome):https://sites.google.com/a/chromium.org/chromedriver/home IEDriverServer(IE):http://selenium-release.storage./index.html operadriver(Opera):https://github.com/operasoftware/operachromiumdriver/releases phantomjs(PhantomJS):http:// MicrosoftWebDriver(Edge):https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver 安装驱动: 将下载好的驱动放到python的安装路径如下: C:\Users\andylijing\AppData\Local\Programs\Python\Python36-32\Scripts
|
|
来自: 馆藏室101 > 《python笔记》