1.安装
pip install selenium
2.下载浏览器对应的Driver
链接地址:https://sites.google.com/a/chromium.org/chromedriver/downloads
根据谷歌系统版本进行下载
chrome://settings/help
将下载好的解压到c:\python27\目录下:
案例1.模拟登陆QQ空间
#coding=utf-8
from selenium import webdriver
chrome=webdriver.Chrome()
chrome.get("https://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=https%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=https%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&pt_qr_app=手机QQ空间&pt_qr_link=https%3A//z.qzone.com/download.html&self_regurl=https%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=https%3A//z.qzone.com/download.html&pt_no_auth=0")
login_from=chrome.find_element_by_id("switcher_plogin")
login_from.click()
uname=chrome.find_element_by_id('u')
passwd=chrome.find_element_by_id('p')
goto=chrome.find_element_by_id('login_button')
uname.send_keys("账号")
passwd.send_keys('密码')
goto.click()