selenium+python3.6学习——第一个脚本

1.下载 geckodriver

在哪下载,为什么下载,参考

http://selenium-python.readthedocs.io/installation.html     1.3Drivers.


2. 解压geckodriver,。添加环境变量:(为什么添加,同样参考上面的官方,我都是按照官方教程做的)

GECKODRIVER

E:\...\geckodriver-v0.15.0-win64


在path中添加:%GECKODRIVER%

3. 编写代码:以下是官方提供的一个打开浏览器,搜索 ,关闭的脚本,把这个脚本保存,起个名字:python_org_search.py

http://selenium-python.readthedocs.io/getting-started.html

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
4.运行,在当前目录下打开命令行,运行python python_org_search.py


5.遇到这个问题:Missing 'marionetteProtocol' field in handshake,这个问题后来查了一下,是我的firefox版本太低了,我的是38.升级到48以后正常。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值