python 验证码生成
2017-09-18 00:00
197 查看
# 验证码生成库 from captcha.image import ImageCaptcha # pip3 install captcha import random number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] alphabet = ['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'] ALPHABET = ['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'] def random_captcha_text(char_set=number, captcha_size=4): # 验证码列表 captcha_text = [] for i in range(captcha_size): # 随机选择 c = random.choice(char_set) # 加入验证码列表 captcha_text.append(c) return captcha_text # 生成字符对应的验证码 def gen_captcha_text_and_image(i): image = ImageCaptcha(width=64 * 2, height=64) # 获得随机生成的验证码 captcha_text = random_captcha_text() # 把验证码列表转为字符串 captcha_text = ''.join(captcha_text) # 生成验证码 captcha = image.generate(captcha_text) image.write(captcha_text, 'captcha/images/' + captcha_text + '_' + str(i) + '.jpg') # 写到文件 num = 100 for i in range(num): gen_captcha_text_and_image(i)
相关文章推荐
- python 生成随机图形验证码
- python学习--------随机验证码生成
- Pyhton每日练习 08 使用 Python 生成类似于下图中的字母+数字验证码图片
- Python3 Pillow生成简单验证码图片
- Python随机数生成验证码
- 使用 Python 生成类数字字母混合验证码图片
- python+ PIL 生成验证码图片
- python生成验证码
- python生成验证码
- python 验证码生成
- python生成验证码
- python生成验证码
- 生成六位验证码python代码
- Python生成验证码实例
- 一个python的验证码生成类
- Python图片处理PIL/pillow/生成验证码/出现KeyError: 和The _imagingft C module is not installed
- python生成网页验证码
- Python 生成随机验证码
- 利用Python生成随机4位验证码