current position:Home>Decoding the verification code of Taobao slider with Python + selenium, the road of information security

Decoding the verification code of Taobao slider with Python + selenium, the road of information security

2021-08-23 11:51:35 Little geese learn python

Preface

Today is Python+Selenium Simulated Login series decipher Taobao slider verification code
I don't say much nonsense , Let's start happily ~

development tool

Python edition : 3.6.4

Related modules :

selenium modular ;

As well as some python Built in modules .

Chromedriver:

Download the driver that matches the Google browser version on your computer in the link below :

http://npm.taobao.org/mirrors/chromedriver/

Environment building

install python And add to environment variable ,pip Install the relevant modules required .

Introduction of the principle

Instantiate a webdriver.Chrome object , For automating the operation of Google browser in our computers :

browser = webdriver.Chrome(executable_path=chromedriverpath, options=chrome_opts)

next , We use it to automatically access Taobao :

browser.get('http://www.taobao.com')

And simulate clicking on the top left of the page " Pro - , Please log in " To enter the login interface of Taobao :
 picture

To be specific , The code implementation is as follows :

button = driver_wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'h')))
button.click()

Automatically fill in the user name and password :

#  Enter the username and password 
username_sender = driver_wait.until(EC.presence_of_element_located((By.ID, 'fm-login-id')))
username_sender.send_keys(username)
password_sender = driver_wait.until(EC.presence_of_element_located((By.ID, 'fm-login-password')))
password_sender.send_keys(password)

The above code directly uses ID To locate the input box :
 picture

Of course, you can also locate elements in web pages in the following ways , How to use it depends on your personal preferences , Beginners don't have to worry too much about these things :

BY.CLASS_NAME
BY.CSS_SELECTOR
BY.LINK_TEXT
BY.NAME
BY.PARTIAL_LINK_TEXT
BY.TAG_NAME
BY.XPATH

After automatically filling in the user name and password , The slider verification code... May appear in the login interface , As shown in the figure below :
 picture

This type of slider verification code requires the user to press and hold the slider , And drag it to the far right . use ActionChains Function directly drag the slider to the far right in one breath to pass the verification :

try:
  slider = browser.find_element_by_xpath("//span[contains(@class, 'btn_slide')]")
  if slider.is_displayed():
    ActionChains(browser).click_and_hold(on_element=slider).perform()
    ActionChains(browser).move_by_offset(xoffset=258, yoffset=0).perform()
    ActionChains(browser).pause(0.5).release().perform()
except:
  pass

Finally, simulate clicking the login button :

#  Click the login button 
button = driver_wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'password-login')))
button.click()

This is the end of the article , Thanks for watching ,Python Information security , The next series will share the painting series

To thank readers , I want to share with you some of my recent collections of programming dry goods , Give back to every reader , I hope I can help you .

Dry goods mainly include :

① 2000 Multiple copies Python e-book ( There should be both mainstream and classic books )

② Python Standard library information ( The most complete Chinese version )

③  Project source code ( Forty or fifty interesting and classic training projects and source code )

④ Python Basic introduction 、 Reptiles 、web Development 、 Big data analysis video ( Suitable for Xiaobai to learn )

⑤ Python Learning Roadmap ( Farewell to bad learning )

All done~ Private letter to get the complete source code ..

Looking back

use Python+Selenium Crack the Spring Airlines slider verification code , The road to information security

use Python+Selenium Crack B Station slider verification code , The road to information security

use Python+hackcaptcha Decipher 12306 Image verification code , The road to information security

Simple implementation of entry-level steganography

copyright notice
author[Little geese learn python],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2021/08/20210823115133481g.html

Random recommended