Python+selenium自動ループメール

6413 ワード

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)

 
転載先:https://www.cnblogs.com/chenbin93/p/9108528.html