python selenium簡單安裝及使用
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()
python selenium簡單安裝及使用