Python 模拟浏览器启动 获取网页内容 自动填表单 自动登录 自动过验证码

食用前准备

python 3.10.10 #二维码的库ddddocr 需要

import time
import ddddocr

源码

# import threading  # 导入threading模块
# from Feishu_SendMsg import *

# Identification verification code
import time
import ddddocr


interval = 100 * 60

# def delayCall():  # 定义方法
#     SendMsg("选题 快快快!!!")

#     timer=threading.Timer(interval,delayCall)  # 每秒运行
#     timer.start()  # 执行方法
    
# if __name__ == '__main__':  #
#     t1=threading.Timer(interval,function=delayCall)  # 创建定时器
#     t1.start()  # 开始执行线程


from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys


# SendMsg("自动填表单")
options = webdriver.ChromeOptions()
options.add_argument('--enable-automation')
options.add_argument('--no-sandbox')
options.add_argument('--disable-extensions')
options.add_argument('--start-maximized')
options.add_argument('--disable-infobars')

prefs = {"profile.default_content_setting_values.autocomplete_enabled": 2}
options.add_experimental_option("prefs", prefs)

# SendMsg("创建 Chrome 浏览器实例")
# 创建 Chrome 浏览器实例
browser = webdriver.Chrome(options=options)

# SendMsg("打开网页")
browser.get('www.tttttttt.com')

# SendMsg("找到账号和密码框元素并输入指定字符串")
username = browser.find_element("name","username")
password = browser.find_element("name","userpass")
usercode = browser.find_element("name","usercode")
img_verifycode = browser.find_element("id","img_verifycode")

# SendMsg("自动填充账号密码")
username.send_keys("11111")
password.send_keys("11111")

verifycodeBase64 = img_verifycode.screenshot_as_base64
ocr = ddddocr.DdddOcr()
res = ocr.classification(verifycodeBase64)
usercode.send_keys(res)
# SendMsg(f"识别并填写验证码: {res}")

# SendMsg("提交表单")
password.send_keys(Keys.RETURN)
# SendMsg("登陆: 提交表单")
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

极客柒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值