当前位置: 首页 > news >正文

【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()

相关文章:

  • Docker使用之java项目工程的部署
  • Linux操作系统-汇编LED驱动程序基础
  • FX-数组的使用
  • 【OCR】OCR开源文字识别工具
  • 力扣大厂热门面试算法题 33-35
  • [CISCN2019 华北赛区 Day1 Web5]CyberPunk --不会编程的崽
  • OPTIONS请求(跨域预检查)
  • Android 12.0 系统修改usb连接电脑mtp和PTP的显示名称
  • [概率论]期中考AB卷题目答案及详解
  • IDEA 配置阿里规范检测
  • Visio 2003简体中文版软件安装教程(附软件下载地址)
  • 【大模型学习记录】db-gpt源码安装问题汇总
  • 计算机毕业设计-基于Python的“哔哩哔哩视频网”视频热度分析
  • Python爬虫-数据采集和处理
  • Linux初识环境变量
  • 【MySQL经典案例分析】 Waiting for table metadata lock
  • 5、React组件事件详解
  • E-HPC支持多队列管理和自动伸缩
  • happypack两次报错的问题
  • Java 内存分配及垃圾回收机制初探
  • laravel5.5 视图共享数据
  • magento 货币换算
  • rabbitmq延迟消息示例
  • swift基础之_对象 实例方法 对象方法。
  • vue--为什么data属性必须是一个函数
  • Web标准制定过程
  • 半理解系列--Promise的进化史
  • 从tcpdump抓包看TCP/IP协议
  • 微信小程序--------语音识别(前端自己也能玩)
  • 一个6年java程序员的工作感悟,写给还在迷茫的你
  • 移动端 h5开发相关内容总结(三)
  • ​​​​​​​GitLab 之 GitLab-Runner 安装,配置与问题汇总
  • #100天计划# 2013年9月29日
  • (echarts)echarts使用时重新加载数据之前的数据存留在图上的问题
  • (Matlab)使用竞争神经网络实现数据聚类
  • (亲测成功)在centos7.5上安装kvm,通过VNC远程连接并创建多台ubuntu虚拟机(ubuntu server版本)...
  • (转)http协议
  • (转)Sublime Text3配置Lua运行环境
  • .[hudsonL@cock.li].mkp勒索加密数据库完美恢复---惜分飞
  • .net core IResultFilter 的 OnResultExecuted和OnResultExecuting的区别
  • .NET Core 实现 Redis 批量查询指定格式的Key
  • .Net mvc总结
  • .NET 设计模式初探
  • .NET/C# 在代码中测量代码执行耗时的建议(比较系统性能计数器和系统时间)...
  • .net的socket示例
  • .NET与java的MVC模式(2):struts2核心工作流程与原理
  • @JoinTable会自动删除关联表的数据
  • []新浪博客如何插入代码(其他博客应该也可以)
  • [20140403]查询是否产生日志
  • [20150707]外部表与rowid.txt
  • [20161214]如何确定dbid.txt
  • [Angular 基础] - 数据绑定(databinding)
  • [Bugku]密码???[writeup]
  • [C#基础]说说lock到底锁谁?
  • [C++ 从入门到精通] 12.重载运算符、赋值运算符重载、析构函数