Python interface Automation 4-Bypass Verification code login (cookie) "Reprint"

Source: Internet
Author: User

From the blog: Shanghai-leisurely

Original address:


Some login interface will have verification code: SMS Verification Code, graphics verification Code, and so on, this kind of login verification code parameters can be obtained from the background (or check the database most directly).

It doesn't matter if you get it, you can bypass the captcha by adding a cookie.

First, catch the login cookie

1. Login will generate a logged in status of the cookie, then only need to add this value directly into the cookie.

2. You can log in manually once, and then crawl this cookie, you need to use the Grab Kit tool fiddler

3. First open the Blog Park login screen, manually enter the account and password (tick the next automatic login)

4. Open the Fiddler Capture tool, refresh the login home page, is the cookie before login

5. After the successful login, then look at the cookie changes, found that two sets of parameters, many of these two sets of parameters is what we want, copy out, one will be useful

II. Cookie Composition Structure

1. Using the grab kit Fidller can only see the cookie name and value two parameters, in fact, the cookie has other parameters

2. The following is a complete cookie composition structure

Cookie ={u ' domain ': U '. ',
U ' name ': U '. Cnblogscookie ',
U ' value ': U ' xxxx ',
U ' expiry ': 1491887887,
U ' path ': U '/',
U ' httponly ': True,
U ' secure ': False}

Name of the Name:cookie

Value:cookie the corresponding value, the dynamically generated

Domain: Server domain name

Expiry:cookie Effective Termination Date

The Path:path property defines which paths on the Web server are under which pages can obtain server-set cookies

HttpOnly: Anti-scripting attack

Secure: Mark the variable in a cookie to indicate that only if the communication protocol between the browser and the Web server is a cryptographic authentication protocol,

The browser submits the appropriate cookie to the server. There is currently only one such protocol, that is, HTTPS.

Third, add a cookie

1. Add a cookie to the session in the following ways

2.set parameter format inside the parentheses

COO = Requests.cookies.RequestsCookieJar ()

Coo.set (' cookie-name ', ' Cookie-value ', path='/', domain='. ')

S.cookies.update (c)

3. Then add the login cookie and fill in the first step fiddler the captured content.

c = Requests.cookies.RequestsCookieJar ()
C.set ('. Cnblogscookie ', ' xxx ')
C.set ('. Cnblogs.AspNetCore.Cookies ', ' xxx ')
S.cookies.update (c)
Print (s.cookies)

4. (Knock the blackboard!!!) Due to recent changes in the login mechanism of the blog Park, 2 additional cookie parameters are required here

C.set (' alwayscreateitemsasactive ', "True")
C.set (' admincookiealwaysexpandadvanced ', "True")

Iv. Reference Code

1. Since the login time is more than 2 cookies, we can first use the Get method to open the login home page, to obtain some cookies

2. Add the cookie that you want to log in to the session

3. After the successful addition, edit the text and title to save to the draft box.

# Coding:utf-8
Import requests

# Open the Login first page to get some cookies
url = "Https://"
headers = {
"User-agent": "mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) gecko/20100101 firefox/44.0 "
} # Get method add a ser-agent to it.

s = requests.session ()
r = S.get (URL, headers=headers,verify=false)
Print S.cookies

# Two cookies required to add a login
c = Requests.cookies.RequestsCookieJar ()

C.set ('. Cnblogscookie ', ' Here is caught ') # fill up the contents of the grab Bag
C.set ('. Cnblogs.AspNetCore.Cookies ', ' Here is caught ') # fill up the contents of the grab Bag
C.set (' alwayscreateitemsasactive ', "True")
C.set (' admincookiealwaysexpandadvanced ', "True")
S.cookies.update (c)
Print S.cookies

# Save edits after successful login
R1 = S.get ("Https://", Headers=headers, Verify=false)

# Save Drafts Box
Url2= "Https://"
BODY = {"__viewstate": "",
"__viewstategenerator": "fe27d343",
"Editor$edit$txbtitle": "This is 3111",
"Editor$edit$editorbody": "<p> here 111:</p>",
"Editor$edit$advanced$ckbpublished": "On",
"Editor$edit$advanced$chkdisplayhomepage": "On",
"Editor$edit$advanced$chkcomments": "On",
"Editor$edit$advanced$chkmainsyndication": "On",
"Editor$edit$advanced$txbentryname": "",
"Editor$edit$advanced$txbexcerpt": "",
"Editor$edit$advanced$tbenrypassword": "",
"Editor$edit$lkbdraft": "Save as draft",
r2 = (Url2, Data=body, Verify=false)
Print R.content

Python interface Automation 4-Bypass Verification code login (cookie) "Reprint"

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: 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.