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)
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.
1 #Coding:utf-82 ImportRequests3 4 #Open the Login first page to get some cookies5URL ="Https://passport.cnblogs.com/user/signin"6headers = {7 "user-agent":"mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) gecko/20100101 firefox/44.0"8}#Get method Add a ser-agent to it.9 Tens =requests.session () Oner = S.get (URL, headers=headers,verify=False) A Prints.cookies - - #two cookies required to add a login thec =Requests.cookies.RequestsCookieJar () - -C.set ('. Cnblogscookie','this is the catch.')#Fill in the contents of the above grab bag -C.set ('. Cnblogs.AspNetCore.Cookies','this is the catch.')#Fill in the contents of the above grab bag +C.set ('alwayscreateitemsasactive',"True") -C.set ('admincookiealwaysexpandadvanced',"True") + s.cookies.update (c) A Prints.cookies at - #save edits after successful login -R1 = S.get ("https://i.cnblogs.com/EditPosts.aspx?opt=1", Headers=headers, verify=False) - - #Save a draft box -Url2="https://i.cnblogs.com/EditPosts.aspx?opt=1" inBODY = {"__viewstate":"", - "__viewstategenerator":"fe27d343", to "Editor$edit$txbtitle":"this is 3111 .", + "Editor$edit$editorbody":"<p> here 111:http://www.cnblogs.com/yoyoketang/</p>", - "editor$edit$advanced$ckbpublished":" on", the "Editor$edit$advanced$chkdisplayhomepage":" on", * "editor$edit$advanced$chkcomments":" on", $ "editor$edit$advanced$chkmainsyndication":" on",Panax Notoginseng "Editor$edit$advanced$txbentryname":"", - "editor$edit$advanced$txbexcerpt":"", the "Editor$edit$advanced$tbenrypassword":"", + "Editor$edit$lkbdraft":"Save as draft", A } ther2 = S.post (Url2, Data=body, verify=False) + PrintR.content
Python interface Automation 4-Bypass Verification code login (cookie)