ReZero's Utopia.

Selenium Qzone登陆

Word count: 169Reading time: 1 min
2017/04/02 Share
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.maximize_window()

driver.get("http://i.qq.com/")

try:
driver.find_element_by_id('login_div')
a = True
except:
a = False

if a == True:
driver.switch_to.frame('login_frame')
driver.find_element_by_id('switcher_plogin').click()
driver.find_element_by_id('u').clear()#选择用户名框
driver.find_element_by_id('u').send_keys('QQ')
driver.find_element_by_id('p').clear()
driver.find_element_by_id('p').send_keys('password')
driver.find_element_by_id('login_button').click()
time.sleep(3)

print(driver.page_source)

driver.close()

这里写图片描述 一开始直接找登陆的账号密码Element
但是却报错显示未查找到该Element
于是打印了下 page_source,查了下view-page
发现的确未有改元素

拜读了大佬的博客才知道这里使用了iframe加载了登陆框
然后就是定位该框,点击账号密码登录输入,点击登陆即可

CATALOG