>  기사  >  백엔드 개발  >  Python을 사용하여 웹 페이지 콘텐츠를 가져오고 자동으로 양식을 채우고 로그인하는 기능을 구현하는 방법

Python을 사용하여 웹 페이지 콘텐츠를 가져오고 자동으로 양식을 채우고 로그인하는 기능을 구현하는 방법

王林
王林앞으로
2023-05-16 13:37:111633검색

라이브러리

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

보충 지식 포인트

다음은 기사에 사용된 ddddocr 라이브러리의 관련 용도를 소개합니다

인증 코드 식별을 위한 Python 라이브러리는 많지만, 이를 식별하는 것은 쉽지 않습니다. use.dddddocr(with The Brother ocr) 라이브러리는 인증 코드 식별을 위한 간단하고 실용적인 라이브러리입니다.

위 내용은 Python을 사용하여 웹 페이지 콘텐츠를 가져오고 자동으로 양식을 채우고 로그인하는 기능을 구현하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 yisu.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제