selenium模块下载

 

在Python中,我们通过pip来下载使用:

pip install selenium
pip install -i https://pypi.doubanio.com/simple/ selenium # 备用地址

浏览器驱动下载

 

除此之外,我们还需要安装浏览器驱动,比较常见的浏览器我们一般选用Chrome和Firefox了,当然IE和Safari也有自己的驱动:

根据系统平台下载对应的浏览器驱动,windows下32位即可:

Selenium - Selenium webdriver的环境配置_microsoft

我们下载浏览器驱动的时候,要注意驱动和浏览器的版本对照,一般在每个版本详情目录中的​​notes.txt​​文件里,存着对应版本关系:

Selenium - Selenium webdriver的环境配置_chrome_02

或者参考下面的对应表:

Chromedriver

Chrome

Chromedriver

Chrome

ChromeDriver v2.46 (2019-02-01)

Supports Chrome v71-73

ChromeDriver v2.45 (2018-12-10)

Supports Chrome v70-72

ChromeDriver v2.44 (2018-11-19)

Supports Chrome v69-71

ChromeDriver v2.43 (2018-10-16)

Supports Chrome v69-71

ChromeDriver v2.42 (2018-09-13)

Supports Chrome v68-70

ChromeDriver v2.41 (2018-07-27)

Supports Chrome v67-69

ChromeDriver v2.40 (2018-06-07)

Supports Chrome v66-68

ChromeDriver v2.39 (2018-05-30)

Supports Chrome v66-68

ChromeDriver v2.38 (2018-04-17)

Supports Chrome v65-67

ChromeDriver v2.37 (2018-03-16)

Supports Chrome v64-66

ChromeDriver v2.36 (2018-03-02)

Supports Chrome v63-65

ChromeDriver v2.35 (2018-01-10)

Supports Chrome v62-64

ChromeDriver v2.34 (2017-12-10)

Supports Chrome v61-63

ChromeDriver v2.33 (2017-10-03)

Supports Chrome v60-62

ChromeDriver v2.32 (2017-08-30)

Supports Chrome v59-61

ChromeDriver v2.31 (2017-07-22)

Supports Chrome v58-60

ChromeDriver v2.30 (2017-06-07)

Supports Chrome v58-60

ChromeDriver v2.29 (2017-04-04)

Supports Chrome v56-58

ChromeDriver v2.28 (2017-03-08)

Supports Chrome v55-57

ChromeDriver v2.27 (2016-12-21)

Supports Chrome v54-56

ChromeDriver v2.26 (2016-12-05)

Supports Chrome v53-55

ChromeDriver v2.25 (2016-10-22)

Supports Chrome v53-55

ChromeDriver v2.24 (2016-09-09)

Supports Chrome v52-54

ChromeDriver v2.23 (2016-08-04)

Supports Chrome v51-53

ChromeDriver v2.22 (2016-06-04)

Supports Chrome v49-52

ChromeDriver v2.21 (2016-01-26)

Supports Chrome v46-50

ChromeDriver v2.20 (2015-10-08)

Supports Chrome v43-48

ChromeDriver v2.19 (2015-08-28)

Supports Chrome v43-47

ChromeDriver v2.18 (2015-08-19)

Supports Chrome v43-46

ChromeDriver v2.17 (2015-07-30)

Supports Chrome v42-43

ChromeDriver v2.16 (2015-06-08)

Supports Chrome v42-45

ChromeDriver v2.15 (2015-03-26)

Supports Chrome v40-43

ChromeDriver v2.14 (2015-01-28)

Supports Chrome v39-42

ChromeDriver v2.13 (2014-12-10)

Supports Chrome v38-41

ChromeDriver v2.12 (2014-10-27)

Supports Chrome v36-40

ChromeDriver v2.11 (2014-10-08)

Supports Chrome v36-40

ChromeDriver v2.10 (2014-05-01)

Supports Chrome v33-36

ChromeDriver v2.9 (2014-02-03)

Supports Chrome v31-34

ChromeDriver v2.8 (2013-12-16)

Supports Chrome v30-33

ChromeDriver v2.7 (2013-11-22)

Supports Chrome v30-33

ChromeDriver v2.6 (2013-11-05)

Supports Chrome v29-32

ChromeDriver v2.5 (2013-11-01)

Supports Chrome v29-32

下载到本地之后,把​​chromedriver.exe​​​移动至Python解释器同级的目录或者​​Scripts​​目录下即可。

测试

 

现在让我们新建一个​​test1.py​​文件,输入如下代码,并运行测试:

from selenium import webdriver
# 创建Chrome WebDriver实例,此路径为驱动程序的路径
driver = webdriver.Chrome()
# firefox浏览器打开
# driver = webdriver.Firefox()
# 加载URL网页
driver.get("http://www.baidu.com/")
# 打印当前页面的title属性内容
print(driver.title)
# 关闭浏览器
driver.quit()

可以看到打开一个浏览器,然后很快就关闭了,本地也打印出了结果,表示安装成功!




 

在Python中,我们通过pip来下载使用:

pip install selenium
pip install -i https://pypi.doubanio.com/simple/ selenium # 备用地址

浏览器驱动下载

 

除此之外,我们还需要安装浏览器驱动,比较常见的浏览器我们一般选用Chrome和Firefox了,当然IE和Safari也有自己的驱动:

根据系统平台下载对应的浏览器驱动,windows下32位即可:

Selenium - Selenium webdriver的环境配置_microsoft

我们下载浏览器驱动的时候,要注意驱动和浏览器的版本对照,一般在每个版本详情目录中的​​notes.txt​​文件里,存着对应版本关系:

Selenium - Selenium webdriver的环境配置_chrome_02

或者参考下面的对应表:

Chromedriver

Chrome

Chromedriver

Chrome

ChromeDriver v2.46 (2019-02-01)

Supports Chrome v71-73

ChromeDriver v2.45 (2018-12-10)

Supports Chrome v70-72

ChromeDriver v2.44 (2018-11-19)

Supports Chrome v69-71

ChromeDriver v2.43 (2018-10-16)

Supports Chrome v69-71

ChromeDriver v2.42 (2018-09-13)

Supports Chrome v68-70

ChromeDriver v2.41 (2018-07-27)

Supports Chrome v67-69

ChromeDriver v2.40 (2018-06-07)

Supports Chrome v66-68

ChromeDriver v2.39 (2018-05-30)

Supports Chrome v66-68

ChromeDriver v2.38 (2018-04-17)

Supports Chrome v65-67

ChromeDriver v2.37 (2018-03-16)

Supports Chrome v64-66

ChromeDriver v2.36 (2018-03-02)

Supports Chrome v63-65

ChromeDriver v2.35 (2018-01-10)

Supports Chrome v62-64

ChromeDriver v2.34 (2017-12-10)

Supports Chrome v61-63

ChromeDriver v2.33 (2017-10-03)

Supports Chrome v60-62

ChromeDriver v2.32 (2017-08-30)

Supports Chrome v59-61

ChromeDriver v2.31 (2017-07-22)

Supports Chrome v58-60

ChromeDriver v2.30 (2017-06-07)

Supports Chrome v58-60

ChromeDriver v2.29 (2017-04-04)

Supports Chrome v56-58

ChromeDriver v2.28 (2017-03-08)

Supports Chrome v55-57

ChromeDriver v2.27 (2016-12-21)

Supports Chrome v54-56

ChromeDriver v2.26 (2016-12-05)

Supports Chrome v53-55

ChromeDriver v2.25 (2016-10-22)

Supports Chrome v53-55

ChromeDriver v2.24 (2016-09-09)

Supports Chrome v52-54

ChromeDriver v2.23 (2016-08-04)

Supports Chrome v51-53

ChromeDriver v2.22 (2016-06-04)

Supports Chrome v49-52

ChromeDriver v2.21 (2016-01-26)

Supports Chrome v46-50

ChromeDriver v2.20 (2015-10-08)

Supports Chrome v43-48

ChromeDriver v2.19 (2015-08-28)

Supports Chrome v43-47

ChromeDriver v2.18 (2015-08-19)

Supports Chrome v43-46

ChromeDriver v2.17 (2015-07-30)

Supports Chrome v42-43

ChromeDriver v2.16 (2015-06-08)

Supports Chrome v42-45

ChromeDriver v2.15 (2015-03-26)

Supports Chrome v40-43

ChromeDriver v2.14 (2015-01-28)

Supports Chrome v39-42

ChromeDriver v2.13 (2014-12-10)

Supports Chrome v38-41

ChromeDriver v2.12 (2014-10-27)

Supports Chrome v36-40

ChromeDriver v2.11 (2014-10-08)

Supports Chrome v36-40

ChromeDriver v2.10 (2014-05-01)

Supports Chrome v33-36

ChromeDriver v2.9 (2014-02-03)

Supports Chrome v31-34

ChromeDriver v2.8 (2013-12-16)

Supports Chrome v30-33

ChromeDriver v2.7 (2013-11-22)

Supports Chrome v30-33

ChromeDriver v2.6 (2013-11-05)

Supports Chrome v29-32

ChromeDriver v2.5 (2013-11-01)

Supports Chrome v29-32

下载到本地之后,把​​chromedriver.exe​​​移动至Python解释器同级的目录或者​​Scripts​​目录下即可。

测试

 

现在让我们新建一个​​test1.py​​文件,输入如下代码,并运行测试:

from selenium import webdriver
# 创建Chrome WebDriver实例,此路径为驱动程序的路径
driver = webdriver.Chrome()
# firefox浏览器打开
# driver = webdriver.Firefox()
# 加载URL网页
driver.get("http://www.baidu.com/")
# 打印当前页面的title属性内容
print(driver.title)
# 关闭浏览器
driver.quit()

可以看到打开一个浏览器,然后很快就关闭了,本地也打印出了结果,表示安装成功!