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

爱蒂网

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

2020-03-14 17:30:58 分类 / 代码专栏 来源 / 互联网

这篇文章主要介绍了python之验证码生成(gvcode与captcha),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

今天向大家总结一下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()

效果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持爱蒂网。

猜你喜欢