1. 程式人生 > >使用selenium登錄QQ空間

使用selenium登錄QQ空間

author log ofo tps button import 之前 密碼 frame

使用selenium登錄QQ空間

打開QQ空間
技術分享圖片

-- coding: utf-8 --
File : 3.登錄qq空間.py
Author: HuXianyong
Date : 2018-09-12 14:56

from selenium import webdriver
chrom = webdriver.Chrome()
url = ‘https://qzone.qq.com/‘
chrom.get(url)
#這裏的意思是我們要選擇賬號登錄之前先要選擇到這個qq登錄方式的白框裏面來做選擇,不然直接在頁面裏面沒有賬號登錄的這個選項這樣會報錯的
chrom.switch_to.frame("login_frame")

#選擇賬號登錄
chrom.find_element_by_id("switcher_plogin").click()

寫入賬號和密碼然後登陸QQ空間
技術分享圖片

- coding: utf-8 --
File : 3.登錄qq空間.py
Author: HuXianyong
Date : 2018-09-12 14:56

from selenium import webdriver

chrom = webdriver.Chrome()
url = ‘https://qzone.qq.com/‘

chrom.get(url)

#這裏的意思是我們要選擇賬號登錄之前先要選擇到這個qq登錄方式的白框裏面來做選擇,不然直接在頁面裏面沒有賬號登錄的這個選項這樣會報錯的

chrom.switch_to.frame("login_frame")
#選擇賬號登錄
chrom.find_element_by_id("switcher_plogin").click()

#找到用戶名對應的ID
username = chrom.find_element_by_id("u")
#給對應的密碼的ID發送登錄賬號
username.send_keys("56273754")
#獲取對應的密碼的ID
passwd = chrom.find_element_by_id("p")
#給對應的密碼的ID發送登錄密碼

passwd.send_keys("mgh****3")
chrom.find_element_by_id("login_button").click()

#退出瀏覽器窗口
chrom.quit()

登陸完成看些結果
技術分享圖片

到此登陸完成

使用selenium登錄QQ空間