目标:QQ空间
url:https://qzone.qq.com/
要求:用账号密码登陆QQ空间,未做无头处理。
请求库:selenium
写法:常规
难度:入门
from selenium import webdriver
from time import sleep
bro = webdriver.Chrome('./chromedriver/chromedriver.exe')
bro.get('https://qzone.qq.com/')
# 切换账号密码登录
# 1.切换iframe标签
bro.switch_to_frame('login_frame')
# 2.定位标签
ch = bro.find_element_by_id('switcher_plogin')
# 3.点击按键
ch.click()
# 定位QQ号和密码标签
name_input = bro.find_element_by_id('u')
pwd_input = bro.find_element_by_id('p')
name_input.send_keys('QQ号')
pwd_input.send_keys('密码')
# 定位登录按键
btn = bro.find_element_by_id('login_button')
btn.click()
sleep(10)
bro.quit()