Home  >  Article  >  Web Front-end  >  Cookie bypass verification code login implementation method

Cookie bypass verification code login implementation method

小云云
小云云Original
2018-01-24 14:10:594255browse

This article mainly introduces you to bypassing the verification code through cookies. Today, I will introduce in detail the implementation code of cookie bypassing the verification code login. Hope it helps everyone.


#coding:utf-8
'''
cookie绕过验证码登录,第一步先访问登录页面获取登录前的cookie,第二步
用fiddler抓到的手动登录的cookie加入cookie中,登录成功,第三步登录成功
后,添加新随笔保存为草稿
'''
import requests,re
requests.packages.urllib3.disable_warnings()
#打开登录
url = "https://passport.cnblogs.com/user/signin"
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36"}
#以下是需要关注的,首先用session保持会话
s = requests.session()
r = s.get(url,headers=headers,verify=False)
print(s.cookies)
#添加登录需要的两个cookie
c = requests.cookies.RequestsCookieJar()
c.set('.CNBlogsCookie','68C248862A9606EBEC754881843E0B126A133EA060D2A8D6F0F120D2BD8C5CB724DE4B12C94D851DC5603655C6C4452F86E345A7537A962EB84BDC6F907A6B8866B9690883AB4BCE702DF76BB340BD372BE67D32')
c.set('.Cnblogs.AspNetCore.Cookies','CfDJ8L5AbrwfmaJLh2XTSoqz06j4vYkUtvsRLF5ibGR_1Z7nRRfKuq9qMe5QGVDwXCroNvfWDjP8XW52IFzjSrfROTzyZ8KgiBupa8nabHR4n_fFMZMjCwwdocbCq8nKHR-7NvjA08dAFPE30In0-Nxs4v1KWNcj1X-9qEFmWM0zcYXaxoWeTxMFvSj0ZQusPpFMB6pNNclrgZ3rHyV_tFzdXvkHTXeTQm0CGsqr2LFBorOmh3YY_w9T45lKY-CcaVA9Yo-p3Bn--HxN8CDuxGJPfX7UWopmeo8r7yKlqs2JlSMv')
s.cookies.update(c)
print(s.cookies)
#登录成功后保存编辑内容
url2 = "https://i.cnblogs.com/EditPosts.aspx?opt=1"
body = {"__VIEWSTATE": "",
    "__VIEWSTATEGENERATOR":"FE27D343",
    "Editor$Edit$txbTitle":"这是绕过登录的标题:上海-悠悠",
    "Editor$Edit$EditorBody":"<p>这里是中文内容: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":"存为草稿",
    }
r2 = s.post(url2,data=body,verify=False)
print(r2.content.decode(encoding=&#39;utf-8&#39;))#通过正则表达式获取保存编辑接口返回页面的内容,判断是否添加草稿成功
t = re.findall(r&#39;value="(.+?)" maxlength&#39;,r2.content.decode(encoding=&#39;utf-8&#39;))
print(t[0])
if t[0] == &#39;这是绕过登录的标题:上海-悠悠&#39;:
  print(&#39;True&#39;)
else:
  print(&#39;False&#39;)

Related recommendations:

Detailed explanation of how to use jQuery.cookie.js and related parameters

jQuery encrypted cookie implementation method

php implements the member login registration page with html plus Session and Cookie

The above is the detailed content of Cookie bypass verification code login implementation method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn