Python verification code interception identification code example

  1. surroundings
  1. The following demo is an interception of the verification code from the official website of Qunar
# - *- coding=utf-8-*-
# CodeDemo.py
# PyCharm  Slade  2019/7/20
# import selenium,os
from selenium import webdriver
from PIL import Image

def aucthcode(coderddr):"""
 Xpath to pass parameter verification code
 The full picture of the page is'code.png'Just name this and you are happy
 The verification code screenshot is named"aucthcode.png
 : param coderddr::return:"""
  
 driver.save_screenshot('code.png')
 element = driver.find_element_by_xpath(coderddr)    #Get the div position of the verification code
 left = element.location['x']+280
 top = element.location['y']+81
 right = left + element.size['width']+int(13)
 bottom = top + element.size['height']+int(2)
 img = Image.open('code.png')
 imgcod = img.crop((left,top,right,bottom))     #Screenshot according to the length and width of the div
 imgcod.save('aucthcode.png')print((left,top,right,bottom))if __name__ =='__main__':
 driver = webdriver.Chrome()
 driver.maximize_window()
 driver.get('https://user.qunar.com/passport/login.jsp')
 driver.find_element_by_css_selector('a.pwd-login').click()aucthcode('//*[@id="captcha"][1]/p[1]')
 driver.quit()

 # img = Image.open('code.png')
 # imgcod = img.crop((1392,393,1490,425))     #Screenshot according to the length and width of the div
 # imgcod.save('aucthcodeN.png')

Note: The interception coordinates of the verification code in the code are not necessarily standard. I get the coordinates of the elements as the basic parameters, and then debug in the main to finally get the coordinates I apply

Run effect display code.png

Run the intercepted verification code effect display aucthcode.png

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Python verification code interception identification code example
Python regular expression example code
Python implements verification code recognition
Python ATM function implementation code example
Python tcp transmission code example analysis
Python requests module session code example
Python object-oriented example
Python3.7 debugging example method
Python SMS bombing code
Python interpolate interpolation example
Python code to find bugs (2)
Python code to find bugs(7)
How to comment python code
Python code to find bugs (3)
Python code to find bugs(9)
Python drawing rose implementation code
Python negative modulus operation example
Python3 logging log package example
Python implements password strength verification
Python output mathematical symbols example
Python install OpenCV sample code
Python code to find bugs(6)
Python iterable object de-duplication example
Python code to find bugs (1)
Python code to find bugs(8)
Python code to find bugs(5)
Python one-dimensional two-dimensional interpolation example
Python right alignment example method