selenium模擬登陸微博
#coding=utf-8
# 導(dǎo)入selenium的瀏覽器驅(qū)動(dòng)接口
from selenium import webdriver
# 要想調(diào)用鍵盤按鍵操作需要引入keys包
from selenium.webdriver.common.keys import Keys
# 導(dǎo)入chrome選項(xiàng)
from selenium.webdriver.chrome.options import Options
# 創(chuàng)建chrome瀏覽器驅(qū)動(dòng)邻奠,無(wú)頭模式
import time
chrome_options = Options()
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(chrome_options=chrome_options)
# 加載微博登錄頁(yè)
driver.get("http://passport.weibo.cn/signin/login?entry=mweibo&r=http%3A%2F%2Fweibo.cn%2F&backTitle=%CE%A2%B2%A9&vt=")
time.sleep(3)
# 找到輸入框怯屉,鍵入用戶名和密碼
driver.find_element_by_id('loginName').send_keys("worio.hainan@163.com")
driver.find_element_by_id('loginPassword').send_keys("Qq94313805")
# 點(diǎn)擊登錄按鈕
driver.find_element_by_id('loginAction').click()
time.sleep(3)
# 快照顯示已經(jīng)成功登錄
print(driver.save_screenshot('jietu.png'))
driver.quit()
參考文章鏈接:https://blog.csdn.net/u010986776/article/details/79266448