【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

相关文章

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

windows和Linux使用命令行计算文件的MD5值

《windows和Linux使用命令行计算文件的MD5值》在Windows和Linux系统中,您可以使用命令行(终端或命令提示符)来计算文件的MD5值,文章介绍了在Windows和Linux/macO... 目录在Windows上:在linux或MACOS上:总结在Windows上:可以使用certuti

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

Python使用Matplotlib绘制3D曲面图详解

《Python使用Matplotlib绘制3D曲面图详解》:本文主要介绍Python使用Matplotlib绘制3D曲面图,在Python中,使用Matplotlib库绘制3D曲面图可以通过mpl... 目录准备工作绘制简单的 3D 曲面图绘制 3D 曲面图添加线框和透明度控制图形视角Matplotlib

Pandas中统计汇总可视化函数plot()的使用

《Pandas中统计汇总可视化函数plot()的使用》Pandas提供了许多强大的数据处理和分析功能,其中plot()函数就是其可视化功能的一个重要组成部分,本文主要介绍了Pandas中统计汇总可视化... 目录一、plot()函数简介二、plot()函数的基本用法三、plot()函数的参数详解四、使用pl

一文教你Python如何快速精准抓取网页数据

《一文教你Python如何快速精准抓取网页数据》这篇文章主要为大家详细介绍了如何利用Python实现快速精准抓取网页数据,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录1. 准备工作2. 基础爬虫实现3. 高级功能扩展3.1 抓取文章详情3.2 保存数据到文件4. 完整示例

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

基于Python打造一个智能单词管理神器

《基于Python打造一个智能单词管理神器》这篇文章主要为大家详细介绍了如何使用Python打造一个智能单词管理神器,从查询到导出的一站式解决,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 项目概述:为什么需要这个工具2. 环境搭建与快速入门2.1 环境要求2.2 首次运行配置3. 核心功能使用指

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格