资源简介
自带requests方式爬取验证码,pillow做图像处理提高识别率,tesseract识别验证码。
代码片段和文件信息
import requests
import random
from PIL import Image
from PIL import ImageEnhance
import pytesseract
import urllib.request
import http.cookiejar
url = ‘http://www.qfzls.com/onlinepay/Login.aspx?om=yssf‘ # 地址格式定义
imgurl = ‘http://www.qfzls.com/onlinepay/yz.aspx‘
# cookie = http.cookiejar.CookieJar()
# cookieProc = urllib.request.HTTPCookieProcessor(cookie)
# print(cookie cookieProc)
# opener = urllib.request.build_opener(cookieProc)
# urllib.request.install_opener(opener)
# html = urllib.request.urlopen(url).read().decode(“UTF8“)
# response = requests.get(url) # 请求获取
# response.encoding = ‘utf8‘ # 请求转码
# html = response.text # 获取网页内容
# print(html)
filename = ‘‘
for j in range(1 9):
m = str(random.randrange(0 10))
filename = filename + m
filename = ‘D:\\image\\‘+filename+‘.bmp‘ # 存成bmp格式
file = open(filename ‘ab‘)
r = requests.get(imgurl)
file.write(r.content)
file.close()
image = Image.open(filename) # filename为验证码的路径加文件名,若是放在项目里可以直接使用文件名调用
enh_bri = ImageEnhance.Brightness(image) # 亮度增强
brightness = 1.5
image = enh_bri.enhance(brightness)
enh_col = ImageEnhance.Color(image) # 色度增强
color = 1.5
image = enh_col.enhance(color)
enh_con = ImageEnhance.Contrast(image) # 对比度增强
contrast = 1.5
image = enh_con.enhance(contrast)
enh_sha = ImageEnhance.Sharpness(image) # 锐度增强
sharpness = 3.0
image = enh_sha.enhance(sharpness)
image.save(filename)
image.show() #展示效果
scode = pytesseract.image_to_string(image)
im = Image.open(filename)
enhancer = ImageEnhance.Color(im)
enhancer = enhancer.enhance(0)
enhancer = ImageEnhance.Brightness(enhancer)
enhancer = enhancer.enhance(2)
enhancer = ImageEnhance.Contrast(enhancer)
enhancer = enhancer.enhance(8)
enhancer = ImageEnhance.Sharpness(enhancer)
im = enhancer.enhance(20)
print(pytesseract.image_to_string(im))
print(scode)
# heade
- 上一篇:使用支持向量机将二维数据三维化划分
- 下一篇:遗传算法python
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论