python 简单粗暴的生产的验证码

import os
import pygame
import random

from pygame.locals import *

count = 0;

生成验证码的函姝

def get_code():

count 绑定全局引用

global count
pygame.init()
target = '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 Za 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'
target = target.replace(' ', '')
rlist = list(target)

print( rlist );

text = rlist[random.randint(0,25)] + rlist[random.randint(0,25)] + rlist[random.randint(0,25)] + rlist[random.randint(0,25)]

print(text)

font = pygame.font.SysFont('Microsoft YaHei', 64)

ftext = font.render(text, True, (65, 83, 130),(255, 255, 255))

控制图片生产的数量

count = count + 1
pygame.image.save(ftext, "D:/code/%d.jpg"%(random.randint(0,100000)))

while count < 10000:
get_code()

欢迎各位大虾指正
原文地址:https://www.cnblogs.com/he-zhi/p/8435863.html