一、目录
-
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下载
注意:Drivers的版本要下载与浏览器相对应的版本,不然会报错
chrome浏览器可以参照链接:http://npm.taobao.org/mirrors/chromedriver/
将下载好的driver放至python根目录下
五、安装pycharm
破解方法可参考链接:https://blog.youkuaiyun.com/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()