欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

python之验证码生成(gvcode与captcha)

时间:2021-09-12 13:59:57|栏目:Python代码|点击:

今天向大家总结一下python在做项目时用到的验证码生成工具:gvcode与captcha

gvcode

全称:graphic-verification-code

安装:

pip install gvcode

使用:

import gvcode

s, v = gvcode.generate()  #序列解包

s.show()  #显示生成的验证码图片

print(v)  #打印验证码字符串

效果:

captcha

安装:

pip install captcha

使用:

from captcha.image import ImageCaptcha
from random import randint
list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
    '', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
chars = ''
for i in range(4):
  chars += list[randint(0, 62)]
image = ImageCaptcha().generate_image(chars)

image.show()

效果:

上一篇:Python流程控制 if else实现解析

栏    目:Python代码

下一篇:利用Pycharm + Django搭建一个简单Python Web项目的步骤

本文标题:python之验证码生成(gvcode与captcha)

本文地址:http://www.codeinn.net/misctech/174428.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有