使用selenuim自动注册protonmail邮箱

任务需求

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

设置代理

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

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

selenuim自动化

 driver.switch_to.frame(0)#切换frame
 NewUser = driver.find_element_by_id("username")
 NewUser.clear()
 NewUser.send_keys()

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

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

 driver.switch_to.frame(1)
 Button_Login = driver.find_element_by_name("submitBtn").click()
 driver.switch_to.default_content()#切换为主文档
 Button_Login = driver.find_element_by_id("confirmModalBtn").click()
 user_click=driver.find_element_by_xpath("//*[@id='mainContainer']/div/div/div[2]/form/footer/button[3]").click()
 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):

      	 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)
                    index1 = len(content)
                    l = content[index1 - 6:]
    # 连接到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()

你可能感兴趣的:(python,selenium)