1.Python 3.6 安装包

1.要加环境变量

2.pip安装PIL库

3.pip安装pytesseract模块

2.tesseract-ocr-setup-4.00.00dev.exe   ---光学识别软件   

D:\Tesseract-OCR\tessdata  要加入环境变量。

3.jTessBoxEditor-2.2.0.zip  训练字库   ---依赖java环境

a

del /a /f /q  "C:\Program Files (x86)\Tesseract-OCR\tessdata\num.traineddata"

copy num.traineddata "C:\Program Files (x86)\Tesseract-OCR\tessdata\"

pause

b

del /a /f /q num.font.exp0.tr

del /a /f /q num.inttemp

del /a /f /q num.normproto

del /a /f /q num.pffmtable

del /a /f /q num.traineddata

del /a /f /q num.shapetable

del /a /f /q num.unicharset

del /a /f /q unicharset

pause

c

echo Run Tesseract for Training..

tesseract.exe num.font.exp0.tif num.font.exp0 nobatch box.train

echo Compute the Character Set..

unicharset_extractor.exe num.font.exp0.box

mftraining -F font_properties -U unicharset -O num.unicharset num.font.exp0.tr

echo Clustering..

cntraining.exe num.font.exp0.tr

echo Rename Files..

rename normproto num.normproto

rename inttemp num.inttemp

rename pffmtable num.pffmtable

rename shapetable num.shapetable

echo Create Tessdata..

combine_tessdata.exe num.

echo. & pause

d

tesseract num.font.exp0.tif num.font.exp0 batch.nochop makebox

4.实例脚本---

#############################################################################################
# 为了不输入验证码,特别写了这个小脚本 #
# 作者:brian #
# 时间:20190109 #
############################################################################################# from selenium import webdriver
from time import sleep
from PIL import Image
import pytesseract
import datetime,time,random
now = datetime.datetime.now()
name = now.strftime("%Y%m%d_%H_%M_%S")
week = datetime.datetime.now().weekday() #配置变量
url = "https://yq.aliyun.com/ziliao/4039425643653"
user = "YourLoginName"
password = "Qwe12345-*" def binarizing(img, threashold):
img = img.convert("L") # 转灰度
pixdata = img.load()
w, h = img.size
for y in range(h):
for x in range(w):
if pixdata[x, y] < threashold:
pixdata[x, y] = 0
else:
pixdata[x, y] = 255
return img
def removeFrame(img, width):
'''
:param img:
:param width: 边框的宽度
:return:
'''
w, h = img.size
pixdata = img.load()
for x in range(width):
for y in range(0, h):
pixdata[x, y] = 255
for x in range(w - width, w):
for y in range(0, h):
pixdata[x, y] = 255
for x in range(0, w):
for y in range(0, width):
pixdata[x, y] = 255
for x in range(0, w):
for y in range(h - width, h):
pixdata[x, y] = 255 def write_log(data):
"""
记录打卡成功的信息,并保存记录,最新记录在第一行。
"""
with open(r"d:\user\7000000000\桌面\pic\打卡成功的记录.txt", 'r+') as f:
content = f.read()
f.seek(0, 0)
f.write(data + "\n" + content) #避免被后台检测到老是同一时间打卡
delayTime = random.randint(1,10)*60
print("等待打卡时间是%s秒。" %delayTime)
for i in range(1,delayTime):
print("等待第%s秒."%i)
time.sleep(1)
print("开始打卡") while True:
"""
因为会识别验证码出错,所以得多次循环去识别,直到识别对为止
"""
try:
dr = webdriver.Chrome()
dr.maximize_window()
dr.get(url)
dr.find_element_by_xpath("//*[@id='username']").send_keys(user)
dr.find_element_by_xpath("//*[@id='password']").send_keys(password)
sleep(2)
#获取验证码
dr.get_screenshot_as_file(r"d:\user\56765453345\桌面\pic\source\%s.png" % name)
location = dr.find_element_by_class_name('yzmImg').location
size = dr.find_element_by_class_name('yzmImg').size
left = location['x']
top = location['y']
right = location['x'] + size['width']
bottom = location['y'] + size['height']
a = Image.open(r"d:\user\56765453345\桌面\pic\source\%s.png" % name)
im = a.crop((left, top, right, bottom))
im.save(r"d:\user\56765453345\桌面\pic\source\%s.png" % name)
pic1 = binarizing(im, 110)
removeFrame(pic1, 3)
pic1.save((r"d:\user\56765453345\桌面\pic\new\%s.tif" % datetime.datetime.now().strftime("%Y%m%d_%H_%M_%S")))
vcode = pytesseract.image_to_string(pic1,lang="num")
new_vcode = vcode.replace(" ", "")
varify_word = new_vcode
if len(varify_word)!= 4 :
print("验证码错误不等于4位",varify_word)
dr.quit()
continue
else:
print("验证码等于4位", varify_word)
dr.find_element_by_xpath("//*[@id='verifyCode']").send_keys(varify_word)
sleep(1)
dr.find_element_by_xpath("//*[@id='loginForm']/div[5]/div/img").click()
sleep(2)
if dr.current_url == "https://yq.aliyun.com/ziliao/":
print("登录百度系统失败")
dr.quit()
continue
else:
print("登录百度系统成功")
except Exception as e:
"""登录过程的出错捕捉"""
print("登录过程中出错了", e)
dr.quit()
continue
sleep(2)
if int(time.strftime("%H%M%S")) - 120000 <= 0:
"""判断打上班卡,还是下班卡(以中午12点基准判断)"""
print("打上班卡去")
try:
if dr.find_element_by_xpath('//*[text()="上班签到"]').get_attribute("disabled") == "true":
print("已经打过卡了,还打个毛线")
dr.quit()
break
else: dr.find_element_by_xpath('//*[text()="上班签到"]').click()
sleep(2)
dr.refresh()
sleep(2)
if dr.find_element_by_xpath('//*[text()="上班签到"]').get_attribute("disabled") == "true": msg_log = "今天工作日是%s,星期%s,打上班卡成功了,打卡时间是%s." % (time.strftime("%Y-%m-%d"), week + 1, time.strftime("%H:%M:%S"))
write_log(msg_log)
print(msg_log)
dr.quit()
break
else:
print("去点击打卡了,但是打卡失败了")
dr.quit()
continue
except Exception as e:
print("打上班卡过程出错了",e)
dr.quit()
continue else: try:
print("打下班卡去")
sleep(2)
startTime = dr.find_element_by_xpath("//div[@class='fc-today']/div/i").text
startTime_srt = datetime.datetime.now().strftime("%Y:%m:%d")
startTime_new = startTime_srt + " " + startTime
print("早上打卡时间是:%s" % startTime_new)
timeArray = time.strptime(startTime_new, "%Y:%m:%d %H:%M:%S")
tartTime_Stamp = int(time.mktime(timeArray))
end_time = int(tartTime_Stamp + 60*9.5*60) #目标下班时间戳
struct_time = time.localtime(end_time)
Format_time = time.strftime("%Y:%m:%d %H:%M:%S",struct_time)
print("目标下班时间是: %s "% Format_time)
now_end_time = int(time.time()) #现在时间戳
if end_time < now_end_time: #下班时间小于现在时间,才可以去打卡
dr.find_element_by_xpath('//*[text()="下班签退"]').click()
sleep(2)
dr.find_element_by_xpath('//*[@id="bsWinPopupBoxModal"]/div/div/div[3]/button[1]').click()
sleep(2)
OffWorkTime = dr.find_element_by_xpath("//div[@class='fc-today']/div/i[2]").text
dr.quit()
#通过网页获取打下班卡的时间
msg_log = "今天工作日是%s,星期%s,打下班卡成功了,打卡时间是%s." % (time.strftime("%Y-%m-%d"), week + 1, OffWorkTime)
write_log(msg_log)
print(msg_log)
break
else:
print("现在时间是: %s,目标下班时间是: %s,还没到打卡时间哦,等等吧 !" %(datetime.datetime.now().strftime("%Y:%m:%d %H:%M:%S"),Format_time))
dr.quit()
break
except Exception as e:
print("打下班卡过程出错了",e)
dr.quit()
continue

来自:https://www.cnblogs.com/MrRead/p/7656800.html

https://www.cnblogs.com/MrRead/p/7656800.html

python语言验证码识别,以后不用老输入验证码了。的更多相关文章

  1. python验证码识别(2)极验滑动验证码识别

    目录 一:极验滑动验证码简介 二:极验滑动验证码识别思路 三:极验验证码识别 一:极验滑动验证码简介   近些年来出现了一些新型验证码,不想旧的验证码对人类不友好,但是这种验证码对于代码来说识别难度上 ...

  2. 验证码识别之w3cschool字符图片验证码(easy级别)

    起因: 最近在练习解析验证码,看到了这个网站的验证码比较简单,于是就拿来解析一下攒攒经验值,并无任何冒犯之意... 验证码所在网页: https://www.w3cschool.cn/checkmph ...

  3. python验证码识别

    关于利用python进行验证码识别的一些想法 用python加“验证码”为关键词在baidu里搜一下,可以找到很多关于验证码识别的文章.我大体看了一下,主要方法有几类:一类是通过对图片进行处 理,然后 ...

  4. Python中机器学习-验证码识别-粗略总结

    #验证码识别# 解决办法:将验证码切割成单个字符训练 遇到问题:验证码字符大小不一或重叠 对上述问题的解决:通过CNN(卷积神经网络)直接就是端到端不分割的识别方式 处理验证码:将图片二值化 输入验证 ...

  5. tensorflow实现验证码识别案例

    1.知识点 """ 验证码分析: 对图片进行分析: 1.分割识别 2.整体识别 输出:[3,5,7] -->softmax转为概率[0.04,0.16,0.8] - ...

  6. 基于SVM的字母验证码识别

    基于SVM的字母验证码识别 摘要 本文研究的问题是包含数字和字母的字符验证码的识别.我们采用的是传统的字符分割识别方法,首先将图像中的字符分割出来,然后再对单字符进行识别.首先通过图像的初步去噪.滤波 ...

  7. 验证码识别--type5

    验证码识别--type5 每一种验证码都是由人设计出来.在设计过程中,可能由于多个方面的原因,造成了这样或那样的可以被利用的漏洞.验证码识别,首先需要解决的问题就是发现这些漏洞--然后利用漏洞解决问题 ...

  8. 基于python语言的tensorflow的‘端到端’的字符型验证码识别源码整理(github源码分享)

    基于python语言的tensorflow的‘端到端’的字符型验证码识别 1   Abstract 验证码(CAPTCHA)的诞生本身是为了自动区分 自然人 和 机器人 的一套公开方法, 但是近几年的 ...

  9. 字符型图片验证码识别完整过程及Python实现

    字符型图片验证码识别完整过程及Python实现 1   摘要 验证码是目前互联网上非常常见也是非常重要的一个事物,充当着很多系统的 防火墙 功能,但是随时OCR技术的发展,验证码暴露出来的安全问题也越 ...

随机推荐

  1. 3、Angular2 Input

    3.理解@input

  2. Spring Data JPA简单使用

    用Spring Data JPA操作数据库 这份教程教你用Spring Data JPA从关系数据库mysql中存储和提取数据.总结来自https://spring.io/guides/gs/acce ...

  3. 位运算(4)——Missing Number

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  4. 微服务学习笔记二:Eureka服务注册发现

    Eureka服务注册发现 服务发现:云端负载均衡,一个基于 REST 的服务,用于定位服务,以实现云端的负载均衡和中间层服务器的故障转移. 1. Service Discovery: Eureka S ...

  5. 对象大小对比之Comparable与Comparator

    一 概述 1.Comparable与Comparator使用背景 数值型数据(byte int short long float double)天生可对比大小,可排序,String实现了Compara ...

  6. SharePoint 2013 - Bootstrap

    1. 在SharePoint 2013中应用Bootstrap时,需要添加以下css: <style> .container{ margin-left:0px; //为了使containe ...

  7. matlab练习程序(Hilbert图像置乱)

    正好刚写了Hibert生成曲线,不如再加一篇应用的程序. 关于Hilbert图像置乱,我在网上搜的应用领域主要集中在数字水印和图像加密上,而这两个领域我都没怎么接触过. 大部分的图像置乱都是如下图的置 ...

  8. JavaScript获取当前网页的源码

    通过 outerHTML document.documentElement.outerHTML 通过异步请求 $.get(window.location.href,function(res){ con ...

  9. Docker 容器中相关软件安装

    Docker 容器中相关软件安装 1.介绍 我们从docker hub下载的centos镜像是只有很少的命令,需要单独安装我们所需的相关软件. 2.安装软件 安装yum-utils软件包 该软件包是辅 ...

  10. SpringMvc-helloword

    说明:在此只说明helloword的简单实现,通过helloword例子先了解springMvc是这样工作的,然后在一步步的研究原理 配置web.xml 1.配置servlet servlet-cla ...