Processing of graphics verification code in Python crawler

Source: Internet
Author: User
Tags base64

When using the Python crawler to log in automatically, encountering the need to enter a graphics verification code, a relatively simple process is to use the Code platform identification Code.

Use over two dozen yards platform, coding rabbit and if fast, if the price is cheaper, the recognition rate is equal. If you need to register two account: Developer account and user account, user account is used to send identification request, the developer account can register the software ID, and to identify the request to bind, can participate in identifying the income of the return.

There are two ways to get the graphics verification code that are currently found:

0x01

You can get the picture directly in the grab bag: Send GET request can get the picture directly (PNG or JPG format), this case can use the content method of Request.get () return value, get picture file, use code platform to identify directly.

0x02

The picture is returned using base64 encryption:

For example, image contains an image file that has been Base64 encrypted. You can restore a picture in the following ways:

 resp = self.s.get (URL, Headers=header, Verify=false, Timeout=10 =json.loads (resp.text) captchaid  =resp_json.get ("  captchaid   " ) imagestr  =resp_json.get ("  image   " ) imgdata  =base64.b64decode (IMAGESTR) file
     =open ( '  captcha.gif  " ),  " WB   " ) file.write (Imgdata) file.close ()  

Picture format is not necessarily a GIF, may be jpg or PNG, if the wrong write, the results can not be opened, the online image decoding web site to verify a piece of format.

Processing of graphics verification code in Python crawler

Related Article

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.