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
code example:
#Baseinfo-__init__#-*-coding:utf-8-*-#TIME:2017/9/23 17:44#Author:yangyangjunloginurl="Https://passport.cnblogs.com/user/signin"loginheaders= { "user-agent":"mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/61.0.3163.79 safari/537.36"}cnblogscookie='get the cookie by grabbing the package tool'cnblogsaspnetcorecookies='get the cookie by grabbing the package tool'Editurl='https://i.cnblogs.com/EditPosts.aspx?opt=1'
#-*-coding:utf-8-*-#TIME:2017/9/23 10:15#Author:yangyangjunImportRequests#Import configuration fileImportBaseinfo#Login Access AddressLoginurl =Baseinfo.loginurl#Request HeaderLoginheaders =baseinfo.loginheaders#Cookie1 after loginCnblogscookie =Baseinfo. Cnblogscookie#Cookie2 after loginCnblogsaspnetcorecookies =Baseinfo. Cnblogsaspnetcorecookies#New Essay orientation addressEditurl =Baseinfo.editurl#Get Sessions =requests.session ()##r = s.get (loginurl,headers = loginheaders,verify = False)#Get Cookiesc =Requests.cookies.RequestsCookieJar ()#two cookies required to add a loginC.set (". Cnblogscookie", Cnblogscookie) C.set ('. Cnblogs.AspNetCore.Cookies', Cnblogsaspnetcorecookies)#Update CookiesS.cookies.update (c) Body= {"__viewstate":"", "__viewstategenerator":"fe27d343", "Editor$edit$txbtitle":"This is the title of the bypass login:-*-BlueSky-*-", "Editor$edit$editorbody":"<p> Here is Chinese content:http://www.cnblogs.com/skyyj/</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 (Editurl, Data=body, verify=False)#Gets the response information returned by the requestPrintR2.content
The values in the body can be viewed in developer mode, such as:
Fill in the title
Response's return contains additional information
--R.status_code #响应状态码
--R.content #字节方式的响应体, will automatically decode for you gzip and deflate compression
--R.headers #以字典对象存储服务器响应头, but this dictionary is very special, the dictionary key is not case-sensitive, if the key does not exist return none
--R.json () #Requests中内置的JSON解码器
--R.url # Get URL
--r.encoding # encoding format
--R.cookies # Get Cookie
--R.raw #返回原始响应体
--R.text #字符串方式的响应体, automatically decoded according to the character encoding of the response head
--R.raise_for_status () #失败请求 (not 200 responses) throws an exception
Python-cookie Bypass Verification Code Login