Python源代碼如下: ...
Python源代碼如下:
# coding=utf-8 from selenium import webdriver from time import sleep from random import randint def auto_throw(target_mail, 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="composebtn"]').click() # 寫信 sleep(1) driver.switch_to.frame("mainFrame") # driver.find_element_by_xpath('//div[@title="陌生人"]/a').click() # 好友分組 driver.find_element_by_xpath('//a[@title="%s"]'%target_mail).click() # 選擇好友 sleep(1) driver.find_element_by_xpath('//input[@title="主題是一封郵件的標題,可不填。"]').send_keys( "第%d封郵件發送成功! 隨機代號為%d!"%(m, randint(100000,1000000))) # 主題 driver.find_element_by_xpath('//a[@name="sendbtn"]').click() # 發送 print("第%d封郵件發送成功!"%m) sleep(1) except: print("發送失敗!") sleep(1) if __name__ == '__main__': print("--------自動迴圈發郵件腳本--------") target_mail = input("請輸入對方郵箱:") username = input("輸入你的QQ郵箱用戶名:") password = input("輸入你的QQ郵箱登錄密碼:") auto_throw(target_mail, username, password)