In today's web pages, image verification codes are one of the most common ways to prevent bots from submitting forms. Here is not detailed introduction, I believe we have met.Now give the code to implement the CAPTCHA image using Python's PiL
In web development often use verification code, in order to prevent the registration of robots or malicious login and query, etc., the role should not be underestimated
But the verification code is not a function can be done, it needs to generate
question No. 0010: use Python to generate an image similar to the letter code in
Reading materials
Idea: First randomly generate a verification code, and then use the Python PiL library to draw the image of the activation code, the
Recently, a small script is written in Python every day, practicing the use of Python syntax.Verification Code Generation:Here used the Python image processing library pil, installation pil the process of a small trouble, on the use of Pillow-win32
Import RandomImport stringFrom PIL import Image,imagedraw,imagefont,imagefilter# The location of the fontFont_path = "/library/fonts/arial.ttf"# Number of digits of the verification codeNumber = 4# Create a picture sizeSize = (100,30)# Picture
#-*-Coding:utf-8-*-"""Created on Mon Mar 21 11:04:54 2017@author: SL"""Import requestsImport time################################################################################################ #先找到对应的爬取验证码连接, for example, I want to crawl the
PiL profile what is PILPIL: is the abbreviation of the Python Image Library, the module of the graphics processing. The main classes include Image,imagefont,imagedraw,imagefilterImport of PiLFirst you need to install the pillow packagePip Install
PiL profile what is PILPIL: is the abbreviation of the Python Image Library, the module of the graphics processing. The main classes include Image,imagefont,imagedraw,imagefilterImport of PiLFirst you need to install the pillow packagePip Install
PiL profile what is PILPIL: is the abbreviation of the Python Image Library, the module of the graphics processing. The main classes include Image,imagefont,imagedraw,imagefilterImport of PiLFirst you need to install the pillow packagePip Install
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.