欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

使用selenuim自动注册protonmail邮箱

程序员文章站 2022-06-15 18:49:17
任务需求①随机生成6-10位由大小写字母和数字组成的邮箱名,至少要有小写字母②自动填写③随机生成密码,由15-30位由大小写字母、数字、特殊字符组成④自动填写,并再次填写以确认密码⑤确认注册,下一步⑥机器人验证/邮箱验证⑦注册成功部分代码from selenium import webdriverimport randomimport timefrom email.parser import Parserfrom email.header import decode_header...

任务需求

①随机生成6-10位由大小写字母和数字组成的邮箱名,至少要有小写字母
②自动填写
③随机生成密码,由15-30位由大小写字母、数字、特殊字符组成
④自动填写,并再次填写以确认密码
⑤确认注册,下一步
⑥机器人验证/邮箱验证
⑦注册成功

部分代码

from selenium import webdriver
import random
import time
from email.parser import Parser
from email.header import decode_header
import poplib
# from email.utils import parseaddr
# import string

chrome_options = webdriver.ChromeOptions()
# 设置代理
chrome_options.add_argument("--proxy-server=socks5://192.168.2.105:1082")

driver = webdriver.Chrome(options=chrome_options)
driver.get('https://mail.protonmail.com/create/new?plan=plus&billing=12&currency=EUR&language=en')
driver.implicitly_wait(10)#设置超时时间

l=""
def user_code():
    flag=1
    while(flag):   
        m = random.randint(6, 10)
        a = [str(i) for i in range(0,10)] + [chr(i_1) for i_1 in range(97,97 + 26)] + [chr(i_2) for i_2 in
                                                                                                 range(65, 65 + 26)]
        code1='{}'.format(''.join(random.choices(a, k=m)))
        n = 0
        for j in code1:
            if j.islower():
                n += 1
        if n >= 1:     
            flag=0
            print(code1)
            return code1

def pwd_code():
    seed = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+=-"
    code2= []
    j=random.randint(15,30)
    for i in range(j):
        code2.append(random.choice(seed))
    salt = ''.join(code2)
    print(salt)
    return salt

def ui_operation():
    driver.switch_to.frame(0)#切换frame
    p1=user_code()
    NewUser = driver.find_element_by_id("username")
    NewUser.clear()
    NewUser.send_keys(p1)

    driver.switch_to.default_content()#切换为主文档

    p2 = pwd_code()
    NewUser = driver.find_element_by_id("password")
    NewUser.clear()
    NewUser.send_keys(p2)
    NewUser = driver.find_element_by_id("passwordc")
    NewUser.clear()
    NewUser.send_keys(p2)

    driver.switch_to.frame(1)
    Button_Login = driver.find_element_by_name("submitBtn").click()
    time.sleep(5)
    driver.switch_to.default_content()#切换为主文档
    Button_Login = driver.find_element_by_id("confirmModalBtn").click()
    time.sleep(3)
    user_click=driver.find_element_by_xpath("//*[@id='mainContainer']/div/div/div[2]/form/footer/button[3]").click()
    time.sleep(2)
    send=driver.find_element_by_id("emailVerification").send_keys("验证邮箱")
    send=driver.find_element_by_xpath("//*[@id='verification-panel']/form[1]/div[1]/div[2]/button").click()

def get_email():
    email = ''
    password = ''  # 这个密码不是邮箱登录密码,是pop3服务密码
    pop3_server = 'pop.qq.com'
    def guess_charset(msg):
        charset = msg.get_charset()
        if charset is None:
            content_type = msg.get('Content-Type', '').lower()
            pos = content_type.find('charset=')
            if pos >= 0:
                charset = content_type[pos + 8:].strip()
        return charset

    def decode_str(s):
        value, charset = decode_header(s)[0]
        if charset:
            value = value.decode(charset)
        return value

    def print_info(msg, indent=0):
        global l
        if (msg.is_multipart()):
            parts = msg.get_payload()
            for n, part in enumerate(parts):
                print_info(part, indent + 1)
        else:
            content_type = msg.get_content_type()
            if content_type == 'text/plain':
                content = msg.get_payload(decode=True)
                charset = guess_charset(msg)
                if charset:
                    content = content.decode(charset)
                    #print(content)
                    index1 = len(content)
                    l = content[index1 - 6:]
                    #print(l)

    # 连接到POP3服务器:
    server = poplib.POP3_SSL(pop3_server, 995)

    # 身份认证:
    server.user(email)
    server.pass_(password)

    # list()返回所有邮件的编号:
    resp, mails, octets = server.list()
    # print(mails)

    # 获取最新一封邮件, 注意索引号从1开始:
    index = len(mails)
    #print('邮件的数量', index)
    resp, lines, octets = server.retr(index)
    # print(lines)
    # lines存储了邮件的原始文本的每一行,
    # 可以获得整个邮件的原始文本:
    msg_content = b'\r\n'.join(lines).decode('utf-8')
    # 稍后解析出邮件:
    msg = Parser().parsestr(msg_content)
    print_info(msg)
    # 关闭连接:
    server.quit()

time.sleep(5)
ui_operation()
time.sleep(20)
get_email()
print(l)
send=driver.find_element_by_id("codeValue").send_keys(l)
setup=driver.find_element_by_xpath("//*[@id='verification-panel']/p[3]/button").click()

本文地址:https://blog.csdn.net/qq_44130722/article/details/107280211