In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how python identifies dynamic CAPTCHA through pillow". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow Xiaobian's train of thought to study and learn "how python recognizes dynamic CAPTCHA through pillow".
In life, when we log in to Weibo and mailbox, we often encounter CAPTCHA. At work, if you want to climb some data, you will also encounter the hindrance of CAPTCHA. This experiment will lead you to understand some of the characteristics of CAPTCHA, and use the pillow library in Python to crack the CAPTCHA.
Environment configuration
Python 2.7
Pillow module
There is a problem is that python2.7 can only be used until 2020, now using 2.7download a lot of things will report an error, it is time to update to python3.7, this article still depends on the 2.7environment.
Download the code to identify the CAPTCHA: python_captcha_jb51.rar
Install the pillow (PIL) library sudo apt-get updatesudo apt-get install python-dev libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tksudo pip2 install pillow identification process
Download the CAPTCHA file python_captcha to the running directory, decompress it, and create a new crack.py file in the python_captcha directory for editing.
#-*-coding:utf8-*-from PIL import Imageim = Image.open ("captcha.gif") # (convert the picture to 8-bit pixel mode) im.convert ("P") # print color histogram print im.histogram ()
Output:
Each digit of the color histogram represents the number of pixels in the picture that contain the color of the corresponding bit.
Each pixel can represent 256 colors, and you will find that the white dot is the most (the position of the white serial number 255, the last bit, as you can see, has 625 white pixels). The red pixel is about 200, and we can sort it to get useful colors.
His = im.histogram () values = {} for i in range (256): values [I] = his [I] for JMagi k in sorted (values.items (), key=lambda XRX [1], reverse = True) [: 10]: print JMagi k
Output:
We get the top 10 colors in the picture, of which 220 and 227 are the red and gray we need. We can use this message to construct a black-and-white binary image.
#-*-coding:utf8-*-from PIL import Imageim = Image.open ("captcha.gif") im.convert ("P") im2 = Image.new ("P", im.size,255) for x in range (im.size [1]): for y in range (im.size [0]): pix = im.getpixel ((ymemx)) if pix = 220 or pix = = 227: # these are the numbers to get im2.putpixel ((ymemx) 0) im2.show ()
Output:
Limitations and problems encountered
#-*-coding:utf8-*-
This line of command stream will report an error when running in windows environment. For specific reasons, please refer to the problem of garbled code in python (2).
This command stream has great limitations, and this is the only type of dynamic purchasing that is identified:
Thank you for your reading, the above is the content of "how python identifies dynamic CAPTCHA through pillow". After the study of this article, I believe you have a deeper understanding of how python identifies dynamic CAPTCHA through pillow, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.