Python3----Exercises (over slide verification)

Source: Internet
Author: User

1 #Import Module2  fromSeleniumImportWebdriver3  fromSelenium.webdriverImportActionchains4  fromSelenium.webdriver.common.byImport by5  fromSelenium.webdriver.common.keysImportKeys6  fromSelenium.webdriver.supportImportExpected_conditions as EC7  fromSelenium.webdriver.support.waitImportwebdriverwait8  fromPILImportImage9 Import TimeTen  One defGet_snap (Driver): ADriver.save_screenshot ('Full_snap.png') -Page_snap_obj = Image.open ('Full_snap.png') -     returnPage_snap_obj the  - defget_image (Driver): -img = Driver.find_element_by_class_name ('geetest_canvas_img') -Time.sleep (2) +Location =img.location -Size =img.size +     Print(size) A  atleft = location['x'] -top = location['y'] -right = left+size['width'] -Bottom = top+size['Height'] -  -Page_snap_obj =Get_snap (Driver) inImage_obj =Page_snap_obj.crop (left, top, right, bottom) -     #image_obj.show () to     returnImage_obj +  - defget_distance (Image1, image2): theStart = 57 *Threhold = 60 $ Panax Notoginseng      forIinchRange (start, image1.size[0]): -          forJinchRange (image1.size[1]): theRGB1 =image1.load () [I, J] +RGB2 =image2.load () [I, J] ARES1 = ABS (rgb1[0]-rgb2[0]) theRes2 = ABS (rgb1[1]-rgb2[1]) +RES3 = ABS (rgb1[2]-rgb2[2]) -             #print (RES1,RES2,RES3) $             if  not(Res1 <threhold andRes2 <threhold andRes3 <threhold): $                 returnI-7 -     returnI-7 -  the defget_tracks (distance): -Distance + = 20#slide a little, and then slide back .Wuyiv =0 thet = 0.2 -Forward_tracks = [] Wu  -Current =0 AboutMID = distance * 3/5 $      whileCurrent <Distance: -         ifCurrent <Mid: -A = 2 -         Else: AA =-3 +  thes = v * t + 0.5 * A * (t**2) -v = v + A *T $Current + =s the Forward_tracks.append (round (s)) the  the     #slide back to the exact position. theBack_tracks = [-1,-1,-1,-2,-3,-2,-2,-2,-2,-+ 1,-1,-1]#total equals -20 -  in     return{'Forward_tracks': Forward_tracks,'Back_tracks': Back_tracks} the  the defCrack (Driver):#Crack slip Authentication About     #1. Click the button to get a picture without a gap thebutton = Driver.find_element_by_class_name ('Geetest_radar_tip') the Button.Click () the  +     #2. Get a picture without a notch -Image1 =get_image (Driver) the Bayi     #3. Click the swipe button to get a picture with a notch thebutton = Driver.find_element_by_class_name ('Geetest_slider_button') the Button.Click () -  -     #4. Get a picture with a notch theImage2 =get_image (Driver) the  the     #5. Compare the pixel points of the two images to find the displacement theDistance =get_distance (Image1, Image2) -  the     #6. Simulation of human behavior, according to the total displacement of the behavior of the trajectory theTracks =get_tracks (distance) the     Print(tracks)94  the     #7. Follow the person's action trajectory first forward slide, then reverse slide thebutton = Driver.find_element_by_class_name ('Geetest_slider_button') the actionchains (Driver). Click_and_hold (Button). Perform ()98  About     #Normal human beings are always confident to start sliding forward, confident performance is crazy acceleration -      forTrackinchtracks['Forward_tracks']:101Actionchains (Driver). Move_by_offset (Xoffset=track, yoffset=0). Perform ()102 103     #as a result, the normal human has paused, returned to the God to discover, the crouching trough, slipped over, and then began to slide backwards104Time.sleep (0.3) the      forBack_trackinchtracks['Back_tracks']:106Actionchains (Driver). Move_by_offset (Xoffset=back_track, yoffset=0). Perform ()107 108     #a small range of shocks, further confusing the background, this step can greatly improve the success rate109Time.sleep (0.1) theActionchains (Driver). Move_by_offset (Xoffset=-3, yoffset=0). Perform ()111Actionchains (Driver). Move_by_offset (Xoffset=3, yoffset=0). Perform () the 113     #after success, the human always likes to silently admire the results of their own jigsaw puzzles, and then reluctantly release the dirty Hands theTime.sleep (0.5) the actionchains (Driver). Release (). Perform () the 117 deflogin_cnblogs (Username,password):118Driver =Webdriver. Chrome ()119     Try: -         #1. Enter your account password to return121Driver.implicitly_wait (3)122Driver.get ('Https://passport.cnblogs.com/user/signin')123 124Input_username = driver.find_element_by_id ('INPUT1') theInput_pwd = driver.find_element_by_id ('Input2')126signin = driver.find_element_by_id ('signin')127  - Input_username.send_keys (username)129 input_pwd.send_keys (password) the Signin.click ()131  the         #2, crack sliding certification133 crack (Driver)134 135Time.sleep (10)#sleep longer and make sure your login is successful136     finally:137 driver.close ()138 139  $ 141 if __name__=='__main__':142Login_cnblogs (username='AAAAA', password='AAAAA')

Python3----Exercises (over slide verification)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.