【Python】使用selenium对Poe批量模拟注册脚本

2024-03-20 02:52

本文主要是介绍【Python】使用selenium对Poe批量模拟注册脚本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

配置好接码api即可实现自动化注册登录试用一体。

运行后会注册账号并绑定邮箱与手机号进行登录试用。

在这里插入图片描述

测试结果30秒一个号

在这里插入图片描述
在这里插入图片描述

import re
import time
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import logging# 配置日志记录
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)# 获取手机验证码
def get_phone_verification_code(url):while True:try:response = requests.get(url)html_content = response.text# 使用正则表达式匹配验证码match = re.search(r'Your Poe verification code is: (\d+)\.', html_content)if match:code = match.group(1)logging.info("提取到的手机验证码: %s", code)return code  # 找到验证码则退出循环并返回验证码logging.info("未找到手机验证码,继续请求...")time.sleep(1)  # 等待 1 秒后再次请求except Exception as e:logging.error("请求手机验证码出错: %s", e)time.sleep(1)  # 出错时等待一段时间后再次请求# 获取邮箱验证码
def get_email_verification_code(url):while True:response = requests.get(url)html_content = response.text# 使用正则表达式匹配 6 位数字match = re.search(r'\b\d{6}\b', html_content)if match:code = match.group()logging.info("提取到的邮箱验证码: %s", code)return code  # 找到验证码则退出循环并返回验证码# 如果页面中没有 6 位数字验证码,使用 BeautifulSoup 进行解析soup = BeautifulSoup(html_content, 'html.parser')pre_element = soup.find('pre')if pre_element:code = pre_element.text.strip()logging.info("提取到的邮箱验证码: %s", code)return code  # 找到验证码则退出循环并返回验证码logging.info("未找到邮箱验证码,继续请求...")time.sleep(1)  # 等待 1 秒后再次请求# 登录循环
def login_loop(driver, wait_time):try:driver.delete_all_cookies()driver.get("https://poe.com/login")# 使用显式等待来等待按钮可见并且可点击use_phone_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), '使用电话')]")))use_phone_button.click()logging.info("点击了 '使用电话' 按钮")# 获取电话号码with open("phone.txt", "r") as file:lines = file.readlines()first_line = lines[0].strip()phone, phone_url = first_line.split("----")logging.info("获取到的电话号码: %s", phone)with open("phone.txt", "w") as file:file.writelines(lines[1:])# 输入电话号码并点击下一步按钮phone_input = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.CSS_SELECTOR, "input.PhoneNumberInput_phoneNumberInput__lTKZv")))phone_input.send_keys(phone)phone_input.send_keys(Keys.RETURN)logging.info("输入电话号码并点击下一步按钮")# 输入电话号码验证码code_input = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.CSS_SELECTOR, "input.VerificationCodeInput_verificationCodeInput__RgX85")))time.sleep(5)verification_code = get_phone_verification_code(phone_url)code_input.send_keys(verification_code)code_input.send_keys(Keys.RETURN)logging.info("输入电话号码验证码")# 获取邮箱with open("emai.txt", "r") as file:lines = file.readlines()first_line = lines[0].strip()email, email_url = first_line.split("----")logging.info("获取到的邮箱: %s", email)with open("emai.txt", "w") as file:file.writelines(lines[1:])# 输入邮件email_input = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.CSS_SELECTOR, "input.EmailInput_emailInput__OfOQ_")))email_input.send_keys(email)email_input.send_keys(Keys.RETURN)# 输入邮件验证码verification_code_input = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.CSS_SELECTOR, "input.VerificationCodeInput_verificationCodeInput__RgX85")))time.sleep(5)logging.info("获取邮箱验证码")verification_code = get_email_verification_code(email_url)logging.info("提交邮箱验证码")verification_code_input.send_keys(verification_code)verification_code_input.send_keys(Keys.RETURN)finally:# 关闭浏览器driver.quit()def main():# 设置等待时间wait_time = 30  # 以秒为单位while True:try:# 创建一个Chrome浏览器实例,启动无痕模式chrome_options = Options()chrome_options.add_argument('user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36')chrome_options.add_argument('--lang=zh-CN')chrome_options.add_argument("--disable-blink-features=AutomationControlled")chrome_options.add_argument('--incognito')  # 启动无痕模式driver = webdriver.Chrome(options=chrome_options)login_loop(driver, wait_time)finally:# 关闭浏览器driver.quit()if __name__ == '__main__':main()

这篇关于【Python】使用selenium对Poe批量模拟注册脚本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/828067

相关文章

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Spring Boot中WebSocket常用使用方法详解

《SpringBoot中WebSocket常用使用方法详解》本文从WebSocket的基础概念出发,详细介绍了SpringBoot集成WebSocket的步骤,并重点讲解了常用的使用方法,包括简单消... 目录一、WebSocket基础概念1.1 什么是WebSocket1.2 WebSocket与HTTP

C#中Guid类使用小结

《C#中Guid类使用小结》本文主要介绍了C#中Guid类用于生成和操作128位的唯一标识符,用于数据库主键及分布式系统,支持通过NewGuid、Parse等方法生成,感兴趣的可以了解一下... 目录前言一、什么是 Guid二、生成 Guid1. 使用 Guid.NewGuid() 方法2. 从字符串创建

Python使用python-can实现合并BLF文件

《Python使用python-can实现合并BLF文件》python-can库是Python生态中专注于CAN总线通信与数据处理的强大工具,本文将使用python-can为BLF文件合并提供高效灵活... 目录一、python-can 库:CAN 数据处理的利器二、BLF 文件合并核心代码解析1. 基础合

Python使用OpenCV实现获取视频时长的小工具

《Python使用OpenCV实现获取视频时长的小工具》在处理视频数据时,获取视频的时长是一项常见且基础的需求,本文将详细介绍如何使用Python和OpenCV获取视频时长,并对每一行代码进行深入解析... 目录一、代码实现二、代码解析1. 导入 OpenCV 库2. 定义获取视频时长的函数3. 打开视频文

Python中你不知道的gzip高级用法分享

《Python中你不知道的gzip高级用法分享》在当今大数据时代,数据存储和传输成本已成为每个开发者必须考虑的问题,Python内置的gzip模块提供了一种简单高效的解决方案,下面小编就来和大家详细讲... 目录前言:为什么数据压缩如此重要1. gzip 模块基础介绍2. 基本压缩与解压缩操作2.1 压缩文

Spring IoC 容器的使用详解(最新整理)

《SpringIoC容器的使用详解(最新整理)》文章介绍了Spring框架中的应用分层思想与IoC容器原理,通过分层解耦业务逻辑、数据访问等模块,IoC容器利用@Component注解管理Bean... 目录1. 应用分层2. IoC 的介绍3. IoC 容器的使用3.1. bean 的存储3.2. 方法注

Python设置Cookie永不超时的详细指南

《Python设置Cookie永不超时的详细指南》Cookie是一种存储在用户浏览器中的小型数据片段,用于记录用户的登录状态、偏好设置等信息,下面小编就来和大家详细讲讲Python如何设置Cookie... 目录一、Cookie的作用与重要性二、Cookie过期的原因三、实现Cookie永不超时的方法(一)

Python内置函数之classmethod函数使用详解

《Python内置函数之classmethod函数使用详解》:本文主要介绍Python内置函数之classmethod函数使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录1. 类方法定义与基本语法2. 类方法 vs 实例方法 vs 静态方法3. 核心特性与用法(1编程客

Python函数作用域示例详解

《Python函数作用域示例详解》本文介绍了Python中的LEGB作用域规则,详细解析了变量查找的四个层级,通过具体代码示例,展示了各层级的变量访问规则和特性,对python函数作用域相关知识感兴趣... 目录一、LEGB 规则二、作用域实例2.1 局部作用域(Local)2.2 闭包作用域(Enclos