使用cookie绕过验证码登录的实现代码
程序员文章站
2022-06-24 17:23:26
本文给大家介绍通过cookie跳转过验证码,今天,就详细的介绍一下cookie绕过验证码登录的实现代码。
#coding:utf-8
'''
cookie绕过...
本文给大家介绍通过cookie跳转过验证码,今天,就详细的介绍一下cookie绕过验证码登录的实现代码。
#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='utf-8'))#通过正则表达式获取保存编辑接口返回页面的内容,判断是否添加草稿成功 t = re.findall(r'value="(.+?)" maxlength',r2.content.decode(encoding='utf-8')) print(t[0]) if t[0] == '这是绕过登录的标题:上海-悠悠': print('true') else: print('false')
总结
以上所述是小编给大家介绍的使用cookie绕过验证码登录的实现代码,希望对大家有所帮助
推荐阅读