h5的頁面要清爽很多,也方便查找
測試環境是macOS+python3+anaconda
#qzone like robot
import time
from selenium import webdriver
qzoneUrl='https://ui.ptlogin2.qq.com/cgi-bin/login?pt_hide_ad=1&style=9&pt_ttype=1&appid=549000929&pt_no_auth=1&pt_wxtest=1&daid=5&s_url=https%3A%2F%2Fh5.qzone.qq.com%2Fmqzone%2Findex'
chromeDriverPath='/Users/vanues/Downloads/chromedriver'#修改你的driver路徑
myQQ=''
myPassword=''
driver = webdriver.Chrome(chromeDriverPath)
driver.get(qzoneUrl)
time.sleep(5)
driver.find_element_by_name('u').clear()
driver.find_element_by_name('u').send_keys(myQQ)
driver.find_element_by_name('p').clear()
driver.find_element_by_name('p').send_keys(myPassword)
driver.find_element_by_id('go').click()
time.sleep(10) #這裏的time.sleep的時間,可以用來人工進行驗證(登陸過多會有一個驗證條)
while(1):
driver.execute_script("window.scrollBy(0,4000);")#滾動屏幕用,用處不大
driver.execute_script("window.scrollBy(0,4000);")
btns=driver.find_elements_by_class_name('like')#查找沒有被點過的點贊按鈕
for btn in btns:
#print("btn:" + str(btn.text) + "\tid:" + str(btn.id))#輸出用,可以關閉
if btn.text=='贊':
btn.click()
else:
continue
print("going to refresh in 60s")
driver.refresh()
time.sleep(60)#每次點完當前頁面所有贊後,60秒刷新一次頁面,再次尋找點贊按鈕
新浪微博點贊可見:微博點贊