from selenium import webdriver
from time import sleep
#範例化瀏覽器物件
bro = webdriver.Chrome(executable_path='./chromedriver')
url = "https://qzone.qq.com/"
bro.get(url)
#使用賬號密碼登入
# 賬號密碼對應標籤在iframe頁面中,需要切換作用域,再定位標籤並點選
bro.switch_to.frame('login_frame')
a_tag = bro.find_element_by_id('switcher_plogin')
a_tag.click()
#錄入賬號密碼
username_tag = bro.find_element_by_id('u')
password_tag = bro.find_element_by_id('p')
username_tag.send_keys('賬號')
password_tag.send_keys('密碼')
#點選登入按鈕
btn = bro.find_element_by_class_name('btn')
btn.click()
sleep(3)
bro.close()