In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "Python+selenium how to crack the jigsaw verification code". The editor shows you the operation process through the actual case, the operation method is simple and fast, and the practicality is strong. I hope this article "how to crack the jigsaw verification code by Python+selenium" can help you solve the problem.
Realization idea
Many websites have jigsaw verification codes.
1. First of all, it is necessary to understand the generation principle of jigsaw verification code.
two。 Make a cracking plan and consider its possibility and success rate.
3. Write a script
The puzzle verification codes of many websites are directly with the help of third-party plug-ins, that is, a kind of solution.
This kind of jigsaw verification code encountered by the author is actually a whole after a number of small fragments have been reassembled. First of all, we have to grab this small fragment image on the website and download it to the local.
Let's first sort out the general idea:
Take pictures of all the fragments-find out their order logic-find the sequence number of the small piece in which they contain the true position of the dark color-calculate the distance based on the width and the sequence number of each piece and the dark piece-move the slider to the right with selenium to this distance.
Core code
Import the necessary packages first:
#-*-coding:utf-8-*-import colorsysimport urllib,os,uuid,re,timefrom PIL import Imagefrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium import webdriver
Capture it and download it locally.
Def create (locapath,fileName): filePath=locapath+'/'+fileName if not os.path.exists (filePath): file=open (filePath,'a+') file.close () return filePathdef downloadImg (): list = openBrowser () for i in range (2): fileName = str (I) +'_ test.jpg' urllib.urlretrieve (list [I], create ('/ Users/zijiawang/Downloads/') FileName)) # download to local time.sleep (3) def openBrowser (): global wzj wzj = webdriver.Firefox () wzj.get ('https://.') Image1_url= wzj.find_elements_by_class_name ('gt_cut_bg_slice') [0] .get _ attribute (' style') image1_url=image1_ url [23:-38] image2_url= wzj.find_elements_by_class_name ('gt_cut_fullbg_slice') [0] .get _ attribute (' style') image2_url=image2_ url [23:-38] return [image1_url,image2_url]
Split and get rgb color
Ef getcolor (image): list = [[XMagne y] for x in range (26) for y in range (2)] listt = [] colors = [] for i in range (len (list)): l = list [I] [0] * 12 weeks = list [I] [1] * 58 listt.append ([12*0.25+i/2*12, 58 girls 0.25 + ((item10)% 2) * 58]) listt.append ([12*0.25+i/2*12) 58% 0.75 + ((item10)% 2) * 58]) listt.append ([12*0.75+i/2*12, 58% 0.25 + ((item10)% 2) * 58]) listt.append ([12*0.75+i/2*12, 58% 0.75 + ((ionization 10)% 2) * 58]) for i in range (len (listt)): colors.append (imageList [I] [0], listt [I] [1]) return colors
Find out the serial numbers of different small fragments.
Def getDeferent (): deferent = [] for i in range [2]: if abs (Color1 [I] [2]-color2 [I]] > 20: print ubib difference:', color1 [I] [2]-color2 [I] [2] deferent.append (I) # print ([idome abs (color1 [0]-color2 [I] [0]), abs (color1 [I] [1]-color2 [I] [1])) Abs (Color1 [I] [2]-color2 [I] [2]) return deferentdef getUPDOWN (): deferent = getDeferent () xlist = [] ylist = [] for i in deferent: if (I / 4)% 2 = = 0: xlist.append (I) else: ylist.append (I) uplist = [] downlist = [] for i in xlist: uplist.append (I / 4) for i in ylist: Downlist.append (I / 4) for i in range (len (uplist)): uplist [I] / = 2 for i in range (len (downlist)): downlist [I] / = 2 func = lambda x Y: x if y in x else x + [y] up = reduce (func, [[],] + uplist) func = lambda x, y: x if y in x else x + [y] down = reduce (func, [[],] + downlist) return up,down
If you write the arrangement method, you will use it.
Def bubble (l): for index in range (len (l)-1,0,-1): for two_index in range (index): if 1 [two _ index] > 1 [two _ index + 1]: 1 [two _ index], 1 [two _ index + 1] = 1 [two _ index + 1], 1 [two _ index] return l
Finally, analyze and assemble the source code.
Def end (): orders = getUPDOWN () orderx = orders [0] ordery = orders [1] orderx print'y Vega Magazine orderX = [145,157,277,265,169,181,253,241,97,109,301,289,73, 85,37,25,1,133,121,49,61,229,217,193,241,255,265,277,181,169,241,253,109,97,289,301,85] orderY = [157,145,265,277,181,169,241,157,253,109,97,109,301,85] 73, 25, 37, 13, 1, 121,133, 61, 49, 217,229,205,193] print upright Xpurs author orderX print upright Ypurs' OrderY for x in range (26): orderX [x]-= 1 orderX [x] / = 12 for y in range (26): orderY [y]-= 1 orderY [y] / = 12 endX = [] endY = [] for i in range (len (orderX)): for j in range (len (orderx)): if orderx [j] = orderX [I]: endX.append (I) break for i In range (len (orderY)): for j in range (len (ordery)): if ordery [j] = = orderY [I]: endY.append (I) break print 'endx:' EndX print 'endy:',endY os.remove (' / Users/zijiawang/Downloads/0_test.jpg') os.remove ('/ Users/zijiawang/Downloads/1_test.jpg') all = [] all = endX+endY # print 'all:',all # system can be tested up to 5 times func = lambda x, y: x if y in x else x + [y] all_old = reduce (func, [[],] + all) # print' all_old:' All_old all_end = bubble (all_old) print 'all_end:',all_end duandata = 1000 for i in range (1 in all_end (all_end)): if all_ end [I]-1 in all_end: pass else: duandata = all_ end [I] print u' breakpoint is:' Duandata guess = [] if duandata! = 1000: if endX! = [] and endY breakpoint = []: print u' breakpoint 1' guess = [duandata,all_end [0]] elif endX = = []: print u' breakpoint 2' guess = [duandata, endY [0]] elif endY = = []: print u' breakpoint 3' guess = [duandata EndX [0]] else: print u'no breakpoint 'guess = [all_end [0]] end_guess = [] print u' guess point:' Guess for i in guess: end_guess.append (I * 12-38) end_guess.append (I * 12-28) end_guess.append (I * 12-20) end_guess.append (I * 12-17) end_guess.append (I * 12-15) print u 'guessed displacement:', end_guess return end_guess
Principal function
If _ _ name__ ='_ main__': downloadImg () color1 = getcolor (Image.open ('/ Users/zijiawang/Downloads/0_test.jpg'). Load ()) color2 = getcolor (Image.open ('/ Users/zijiawang/Downloads/1_test.jpg'). Load () guess = end () for i in guess: print I Wzj.title try: ele = wzj.find_element_by_xpath ('/ / div [@ class= "gt_slider_knob gt_show"]') except: ele = wzj.find_element_by_xpath ('/ / div [@ class= "gt_slider_knob gt_show moving"]') ActionChains (wzj). Click_and_hold (ele). Perform () ActionChains (wzj). Move_to_element_with_offset (ele, 0J I). Perform ()
This is the end of the introduction on "how to crack the jigsaw verification code by Python+selenium". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.