window下python3+selenium3安装

一、目录

  • windows下python3.6.5下载安装

  • windows下selenium3下载安装

  • windows下pycharm下载安装 (python代码编辑器)

  • windows下chrome下载安装

  • drivers下载

二、下载链接准备

python官方下载链接: https://www.python.org/downloads/  

pycharm官方下载链接:http://www.jetbrains.com/pycharm/download/#section=windows(这里选择Professional版,先下载之后破解使用)

chrome浏览器下载链接: https://chrome.en.softonic.com/

三、软件安装

1)python安装

下载好python之后,点击exe文件,选择安装目录,成功之后,windows+R 输入cmd,弹出命令行窗口,输入python, 查看python版本

Microsoft Windows [版本 10.0.16299.371]

(c) 2017 Microsoft Corporation。保留所有权利。

C:\Users\FE>python

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>>

2.selenium安装

安装好python3之后,默认就有pip, 使用pip安装selenium

命令行输入如下命令:

pip install selenium

三、Chrome安装

四、Drivers下载

Chrome:

https://sites.google.com/a/chromium.org/chromedriver/downloads

Edge:

https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

Firefox:

https://github.com/mozilla/geckodriver/releases

Safari:

https://webkit.org/blog/6900/webdriver-support-in-safari-10/

注意:Drivers的版本要下载与浏览器相对应的版本,不然会报错

chrome浏览器可以参照链接:http://npm.taobao.org/mirrors/chromedriver/

将下载好的driver放至python根目录下

五、安装pycharm

破解方法可参考链接:https://blog.csdn.net/u014044812/article/details/78727496

六、第一个webdriver示例

from selenium import webdriver

from selenium.common.exceptions import TimeoutException

from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0

from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0

# Create a new instance of the Firefox driver

driver = webdriver.Chrome()

# go to the google home page

driver.get("http://www.google.com")

# the page is ajaxy so the title is originally this:

print driver.title

# find the element that's name attribute is q (the google search box)

inputElement = driver.find_element_by_name("q")

# type in the search

inputElement.send_keys("cheese!")

# submit the form (although google automatically searches now without submitting)

inputElement.submit()

try:

# we have to wait for the page to refresh, the last thing that seems to be updated is the title

WebDriverWait(driver, 10).until(EC.title_contains("cheese!"))

# You should see "cheese! - Google Search"

print driver.title

finally:

driver.quit()

转载于:https://my.oschina.net/ps22/blog/1830970

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值