In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "Python how to achieve square system sliding CAPTCHA recognition", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Python how to achieve square system sliding CAPTCHA recognition" this article.
Step 1: click on data analysis
Click the slide button and a request will be sent to / zfcaptchaLogin
Request content
"type": "verify"rtk": "6cfab177-afb2-434e-bacf-06840c12e7af"time": "1624611806948"mt": "W3sieCI6OTY1LCJ5IjoxNjksInQiQiQiOjE2MjQ2MTE4MDY4Njh9LHsieCI6OTY1LCJ5IjoxNjksInQiQiOjE2MjQ2MTE4MDY5NDh9XQ =" instanceId ":" zfcaptchaLogin "extend": "eyJhcHBOYW1lIjoiTmV0c2NhcGUiLCJ1c2VyQWdlbnQiOiJNb3ppbGxhLzUuMCAoTWFjaW50b3NoOyBJbnRlbCBNYWMgT1MgWCAxMF8xNV83KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvOTEuMC40NDcyLjEwNiBTYWZhcmkvNTM3LjM2IiwiYXBwVmVyc2lvbiI6IjUuMCAoTWFjaW50b3NoOyBJbnRlbCBNYWMgT1MgWCAxMF8xNV83KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvOTEuMC40NDcyLjEwNiBTYWZhcmkvNTM3LjM2In0="
Decrypt mt and extend through base64 to get the decrypted value.
# mt [{"x": 965,1624611806868}, {"x": 965,1624611806868}, {"x": 965," y ": 1624611806948}] # extend {" appName ":" Netscape "," userAgent ":" Mozilla/5.0 (Macintosh; Intel Mac OS X 1015007) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36 "," appVersion ":" 5.0 (Macintosh) Intel Mac OS X 10: 15: 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36 "}
Mt is the click behavior of the user, x is the value on the X axis, y is the value on the Y axis, and t is the timestamp. Through a large number of click analysis, it is found that the minimum value of x is 950, and it is concluded that 950 is the starting point of the X axis, and there is no fixed value of y at random.
Extend is to request quality content.
Step 2: slide the CAPTCHA image analysis and calculate the sliding distance x value
The image is grayed out, and the color value of a certain point of the image can be obtained by getpixel. The higher the color value is, the lighter the image is, so looking for 50 consecutive vertical pixels is getpixel (x, y) > getpixel (x, y) (X axis = x than X axis = x axis = X axis).
The image is scanned, and the color of the image is darker than that when the scanning height is 50 and the scanning height is 130.
From PIL import Imageimport matplotlib.pyplot as pltimport numpy as np scanf_height= 50 # scan height img = Image.open ("zfcaptchaLogin.png") def contrast (imgl, x, y paper scanftings height): # the number of yellow box color values lighter than the red box color value count = 0 for i in range (scanf_height): if imgl.getpixel ((x, yardi)) > imgl.getpixel ((x, yardi)): count + = 1 # when count = scanf_height Represents the yellow stripe area, the overall red stripe area has a light color value. The verification code frame position return count def scanf (img): imgx, imgy = img.size imgl = img.convert ('L') # Image Grey plt.yticks ([]) plt.xticks ([i for i in range (0, imgx, 25)]) plt.imshow (img) plt.pause (0) for y in range (0, imgy-scanf_height) 10): plt.pause (0.01) plt.clf () plt.yticks ([]) plt.xticks ([i for i in range (0, imgx, 25)]) plt.imshow (imgl, cmap=plt.cm.gray) for x in range (1, imgx-1, 1): plt.pause (0.0001) plt.plot Y+scanf_height], color='white') plt.plot ([xjime x], [y, y+scanf_height], color='red') plt.plot ([xjin1 y+scanf_height], [y, y+scanf_height], color='yellow') count = contrast (imgl, xpene y, scanf_height) plt.title ('count: {}' .format (count)) print ("xjingy= [{}] {}], the number of yellow stripes with lighter color than the red stripes: {} ".format (xtraining y, count) if count = = scanf_height: return scanf (img) plt.show ()
Optimize the code to calculate x, y values
Import jsonimport randomimport timefrom io import BytesIO from PIL import Image class ZfCaptchaRecognit (object): def _ init__ (self, img_path): self.img = Image.open (img_path) def _ get_xy (self): # calculate the x _ is_dividing_line y value def _ is_dividing_line (img_l, x Y): for n in range (50): # looking for 50 consecutive pixels in the vertical direction, all of which are darker than X=x+1 if y + n > = img_l.size [1] or x > = img_l.size [0]-1: return False if img_l.getpixel ((xylene 1, y + n))-img_l.getpixel ((x) Y + n) < 2: return False return True img_l = self.img.convert ("L") for x in range (img_l.size [0]): for y in range (img_l.size [1]): if _ is_dividing_line (img_l, x, y): return (x Y) def show_tag (self): # show syncopation point X, Y = self._get_xy () img2 = Image.new ("RGB", self.img.size, (255,255,255)) for x in range (self.img.size [0]): for y in range (self.img.size [1]): pix = self.img.getpixel ((x) Y) img2.putpixel ((x, y), pix) if x = = X or y = = Y: img2.putpixel ((x, y), 225) img2.save ("show_tag.png") img2.show () captcha = ZfCaptchaRecognit ("zfcaptchaLogin.png") captcha.show_tag () step 3: generate submission parameters
Through step 1, it is concluded that the minimum value of x is 950 and the value of y is irregular.
The approximate format data for the submission parameter mt is
[{"x": 950 + sliding distance + floating value, # floating value range obtained by analyzing the submitted parameters "y": random.randint (150,190), # irregular, tentatively within the range of 150,190 "t": int (time.time () * 1000)}, # timestamp.]
Get the mt parameter
Import jsonimport randomimport timefrom io import BytesIO from PIL import Image class ZfCaptchaRecognit (object): def _ init__ (self, img_stream): obj = BytesIO (img_stream) self.img = Image.open (obj) def _ get_xy (self):. Def generate_payload (self): base_x = 950X, Y = self._get_xy () payloads = [{"x": base_x + random.randint (5,20), "y": random.randint (150,190), "t": int (time.time () * 1000)}] for i in range (random.randint (15) 30): # float last_payload = payloads [- 1] .copy () payloads [0] ["x"] + = random.choice ([0] * 8 + [1,-1] * 2 + [2,-2]) last_payload ["t"] + = random.randint (1) 20) last_payload ["y"] + = random.choice ([0] * 8 + [1,-1] * 2 + [2,-2]) payloads.append (last_payload) payloads [- 1] ["x"] = base_x + random.randint (10,20) + X return json.dumps (payloads) captcha = ZfCaptchaRecognit ("zfcaptchaLogin.png") captcha. Generate_payload () above is all the contents of the article "how to realize the sliding CAPTCHA recognition of the square system by Python". Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.