selenium 安装

关于 selenium 安装,

 

第一步,安装Python:

https://www.python.org/downloads 选择3.x版本(避免2.x 烦人的编码问题)

 

第二步,关于 SetupTools + pip(这两个工具目的是为了下载selenium),

python 2.7 + windows版本已经集成这两个工具,不用安装

如需安装,参考:http://blog.youkuaiyun.com/chinajobs/article/details/52861692

 

第二步,selenium 安装

pip install selenium,该命令会安装最新版本

 

第三步步,chrome以及 浏览器驱动安装

请选择和 浏览器 版本 匹配的chromedriver 驱动,参考 http://blog.youkuaiyun.com/wang8978/article/details/52934506

将 chromedriver.exe 所在目录加入PATH环境变量,如:D:\PATH  ,注意 路径中 空格问题

测试语句:

 1 from selenium import webdriver
 2 from selenium.common.exceptions import TimeoutException
 3 from selenium.webdriver.support.ui import WebDriverWait
 4 from selenium.webdriver.support import expected_conditions as EC
 5 
 6 
 7 driver = webdriver.Chrome()
 8 driver.get("http://www.baidu.com")
 9 
10 driver.find_element_by_id("kw").send_keys("博客园")
11 driver.find_element_by_id("su").click()
12 
13 try:
14     # we have to wait for the page to refresh, the last thing that seems to be updated is the title
15     WebDriverWait(driver, 5).until(EC.title_contains("博客园"))
16 
17     # You should see "博客园_百度搜索"
18     print(driver.title) # Python 3 中语法:print("display something ...")
19 
20 finally:
21     driver.quit()

 

转载于:https://www.cnblogs.com/lightyear-one/p/6279387.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值