Python源代碼如下: ...
Python源代碼如下:
# coding=utf-8 from selenium import webdriver from time import sleep from random import randint def auto_throw(target_qq, username, password): """自動迴圈送賀卡""" driver = webdriver.Chrome() driver.get("https://mail.qq.com") driver.set_window_size(1100, 580) sleep(1) # 切換iframe表單 driver.switch_to.frame("login_frame") driver.find_element_by_xpath('//*[@id="u"]').send_keys(username) driver.find_element_by_xpath('//*[@id="p"]').send_keys(password) driver.find_element_by_xpath('//*[@id="login_button"]').click() sleep(1) # 將表單切回到最外層 driver.switch_to.default_content() sleep(2) m = 0 while True: try: m += 1 driver.switch_to.default_content() driver.find_element_by_xpath('//*[@id="folder_card"]').click() # 賀卡 sleep(2) # 切換iframe表單 driver.switch_to.frame("mainFrame") driver.find_element_by_xpath('//*[@id="preview_1072308"]/img').click() # 兒童節 # 將表單切回到最外層 driver.switch_to.default_content() sleep(2) driver.find_element_by_xpath('//div[@class="dialog_operate"]/a').click() # 發送 sleep(2) driver.find_element_by_xpath('//a[@title="%[email protected]"]'%target_qq).click() sleep(1) driver.find_element_by_xpath('//*[@id="GreetingCard_QMDialog_content"]').clear() driver.find_element_by_xpath('//*[@id="GreetingCard_QMDialog_content"]').send_keys("第%d張賀卡發送成功!代號%d!"%(m,randint(10000,100000))) sleep(2) driver.find_element_by_xpath('//*[@id="GreetingCard_QMDialog_sendbtn"]').click() # 發送 print("第%d張賀卡發送成功!"%m) sleep(2) except: print("送卡失敗!") sleep(2) if __name__ == '__main__': print("--------自動送賀卡腳本--------") target_qq = input("請輸入對方qq號:") username = input("輸入你的QQ郵箱用戶名:") password = input("輸入你的QQ郵箱登錄密碼:") auto_throw(target_qq, username, password)