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

Source: Internet
Author: User

Objective

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 '. cnblogs.com ',
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='. xxx.com ')

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)

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://passport.cnblogs.com/user/signin"
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 ', ' xxx ') # fill up the contents of the grab Bag
C.set ('. Cnblogs.AspNetCore.Cookies ', ' xxx ') # fill up the contents of the grab Bag
S.cookies.update (c)
Print S.cookies

# Save edits after successful login
Url2= "Https://i.cnblogs.com/EditPosts.aspx?opt=1"
BODY = {"__viewstate": "",
"__viewstategenerator": "fe27d343",
"Editor$edit$txbtitle": "This is the title of the bypass login: Shanghai-leisurely",
"Editor$edit$editorbody": "<p> here is Chinese content:http://www.cnblogs.com/yoyoketang/</p>",
"Editor$edit$advanced$ckbpublished": "On",
"Editor$edit$advanced$chkdisplayhomepage": "On",
"Editor$edit$advanced$chkcomments": "On",
"Editor$edit$advanced$chkmainsyndication": "On",
"Editor$edit$lkbdraft": "Save as draft",
}
r2 = S.post (Url2, Data=body, Verify=false)
Print R.content

Interested in Python interface automation, you can add Python interface Automation QQ Group: 226296743

You can also pay attention to my personal public number:

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

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.