一、先安装selenium
命令行模式下,pip install selenium
二、代码实现
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time #用来延时
from selenium import webdriver
# driver = webdriver.Chrome("D:/Program Files/360Chrome/Chrome/Application/360chrome.exe")
driver = webdriver.Firefox()
print("12346")
driver.get("https://qzone.qq.com/")
print("world")
driver.switch_to.frame('login_frame')
driver.find_element_by_id('switcher_plogin').click()
driver.find_element_by_name('u').clear()
time.sleep(5)
driver.find_element_by_name('u').send_keys('qq号') # 此处输入你的QQ号
time.sleep(5)
driver.find_element_by_name('p').clear()
time.sleep(5)
driver.find_element_by_name('p').send_keys('qq密码') # 此处输入你的QQ密码
time.sleep(5)
driver.execute_script("document.getElementById('login_button').parentNode.hidefocus=false;")
time.sleep(5)
driver.find_element_by_xpath('//*[@id="loginform"]/div[4]/a').click()
time.sleep(5)
driver.find_element_by_id('login_button').click()
time.sleep(5) # 因为我曾经是QQ会员,所以每次登陆时都会提醒我要不要再续费的弹窗...
driver.find_element_by_id('dialog_button_1').click() # 这个地方是我把那个弹窗给点击了,配合上面的延时用的,延时是等待那个弹窗出现,然后此处点击取消
btns = driver.find_elements_by_css_selector('a.item.qz_like_btn_v3') # 此处是CSS选择器
for btn in btns:
btn.click()