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("登陆: 提交表单")

猜你喜欢

转载自blog.csdn.net/qq_39162566/article/details/129707575