In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 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 how to crack sliding CAPTCHA, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this Python article on how to crack sliding CAPTCHA. Let's take a look.
The idea of cracking sliding CAPTCHA
For this kind of verification, if we directly simulate the form request, the tedious authentication parameters and authentication process will break your eggs. We can use selenium to drive the browser to solve this problem, which is roughly divided into the following steps
1. Enter the user name and password
2. Click the button to verify and pop up the picture with no gap.
3. Get a picture without a gap
4. Click the slide button to pop up the notched picture
5. Get a picture with a gap
6. Compare the two pictures to find out the gap, that is, the sliding displacement
7. according to people's behavior habits, the total displacement is cut into small displacements.
8. Move according to displacement
9. Complete login
Realize
Code realization of displacement movement
Def get_track (distance):''get the moving track and imitate the sliding behavior of people Basic formula of uniform acceleration followed by uniform deceleration: ① v=v0+at ② sluggish v0t + (1stroke 2) at ²③ v ²- v0 ²= 2as: param distance: distance to move: return: store the distance moved every 0.2s # initial velocity v0,0 # unit time is 0.2s to calculate the trajectory, the trajectory is the displacement within 0.2 # displacement / track list An element in the list represents a displacement of 0.2s tracks= [] # the current displacement current=0 # reaches midvalue and begins to decelerate mid=distance * 4Comp5 distance + = 10 # first slide through a little, and then slide back to while current in reverse.
< distance: if current < mid: # 加速度越小,单位时间的位移越小,模拟的轨迹就越多越详细 a = 2 # 加速运动 else: a = -3 # 减速运动 # 初速度 v0 = v # 0.2秒时间内的位移 s = v0*t+0.5*a*(t**2) # 当前的位置 current += s # 添加到轨迹列表 tracks.append(round(s)) # 速度已经达到v,该速度作为下次的初速度 v= v0+a*t # 反着滑动到大概准确位置 for i in range(3): tracks.append(-2) for i in range(4): tracks.append(-1) return tracks对比两张图片,找出缺口def get_distance(image1,image2): ''' 拿到滑动验证码需要移动的距离 :param image1:没有缺口的图片对象 :param image2:带缺口的图片对象 :return:需要移动的距离 ''' # print('size', image1.size) threshold = 50 for i in range(0,image1.size[0]): # 260 for j in range(0,image1.size[1]): # 160 pixel1 = image1.getpixel((i,j)) pixel2 = image2.getpixel((i,j)) res_R = abs(pixel1[0]-pixel2[0]) # 计算RGB差 res_G = abs(pixel1[1] - pixel2[1]) # 计算RGB差 res_B = abs(pixel1[2] - pixel2[2]) # 计算RGB差 if res_R >Threshold and res_G > threshold and res_B > threshold: return I # the distance you need to move to get the picture def merge_image (image_file,location_list): "stitching picture: param image_file:: param location_list:: return:" im = Image.open (image_file) im.save ('code.jpg') new_im = Image.new (' RGB') (260116)) # cut the unordered picture into 52 small pictures im_list_upper = [] im_list_down = [] # print (location_list) for location in location_list: # print (location ['y']) if location ['y'] =-58: # upper half im_list_upper.append ((abs (location ['x']), 58 Abs (location ['x']) + 10116)) if location ['y'] = 0: # bottom half of im_list_down.append (im.crop ((abs (location ['x']), 0 for im in im_list_upper abs (location ['x']) + 10 for im in im_list_upper 58)) x_offset = 0 for im in im_list_upper: new_im.paste (im, (x_offset) (0)) # put the small picture on the new blank picture x_offset + = im.size [0] x_offset = 0 for im in im_list_down: new_im.paste (im, (xerooffset.58)) x_offset + = im.size [0] new_im.show () return new_imdef get_image (driver) Div_path):''download the unordered picture and splice it together to get the complete picture: param driver:: param div_path:: return:' 'time.sleep (2) background_images = driver.find_elements_by_xpath (div_path) location_list = [] for background_image in background_images: location = {} result = re .findall ('background-image: url ("(. *?)") Background-position: (. *?) px (. *?) px ', background_image.get_attribute (' style') # print (result) location ['x'] = int (result [0] [1]) location ['y'] = int (result [0] [2]) image_url = result [0] [0] location_list.append (location) print ('=') image_url = image_url.replace ('webp' 'jpg') #' replaces url http://static.geetest.com/pictures/gt/579066de6/579066de6.webp' image_result = requests.get (image_url). Content # with open ('1.jpg image_file image_file = BytesIO (image_result) # is an unordered picture image = merge_image (image_file) Location_list) return image move print ('first step, click the slide button') ActionChains (driver). Click_and_hold (on_element=element). Perform () # Click the left mouse button Press and hold time.sleep (1) print ('second step, drag element') for track in track_list: ActionChains (driver). Move_by_offset (xoffset=track, yoffset=0). Perform () # move the mouse to the distance from the current position (xQuery y) if l threshold and res_G > threshold and res_B > threshold: return I # the distance def main_check_code (driver Element): "" drag the identification code: param driver:: param element:: return: "" image1 = get_image (driver,'/ div [@ class= "gt_cut_bg gt_show"] / div') image2 = get_image (driver) '/ / div [@ class= "gt_cut_fullbg gt_show"] / div') # x coordinates of the location of the gap in the picture # 2 compare all RBG pixels of the two images Get the x value of different pixels, that is, the distance to be moved is l = get_distance (image1, image2) print ('lumped magic Magazine l) # 3 to get the moving track track_list = get_track (l) print (' first step, click the sliding button') ActionChains (driver). Click_and_hold (on_element=element). Perform () # Click the left mouse button Press and hold time.sleep (1) print ('second step, drag element') for track in track_list: ActionChains (driver). Move_by_offset (xoffset=track, yoffset=0). Perform () # move the mouse to the current position (XMagi y) time.sleep (0.002) # if l > 100: ActionChains (driver). Move_by_offset (xoffset=-random.randint (2Magne5) Yoffset=0) .perform () time.sleep (1) print ('third step Release the mouse') ActionChains (driver) .release (on_element=element). Perform () time.sleep (5) def main_check_slider (driver): "check whether the slide button loads: param driver:: return:" while True: try: driver.get ('http://www.cnbaowen.net/api/geetest/') element= WebDriverWait (driver, 30) " EC.element_to_be_clickable ((By.CLASS_NAME, 'gt_slider_knob')) if element: return element except TimeoutException as e: print (' timeout error Continue') time.sleep (5) if _ _ name__ ='_ _ main__': try: count = 6 # recognize up to 6 times driver = webdriver.Chrome () # wait for the slide button to load element = main_check_slider (driver) while count > 0: main_check_code (driver Element) time.sleep (2) try: success_element = (By.CSS_SELECTOR, '.gt_holder .gt _ ajax_tip.gt_success') # get the success flag print (' suc=' Driver.find_element_by_css_selector ('.gt _ holder .gt _ ajax_tip.gt_success') success_images = WebDriverWait (driver, 20) .initiate (EC.presence_of_element_located (success_element)) if success_images: print (' successfully identified!') Count = 0 break except NoSuchElementException as e: print ('recognition error Continue') count-= 1 time.sleep (2) else: print ('too many attempt check code') exit ('exit program') finally: driver.close () this is the end of the article on "how to crack sliding CAPTCHA by Python". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to crack sliding CAPTCHA by Python". If you want to learn more, you are 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.