码迷,mamicode.com
首页 > 其他好文 > 详细

session关联接口

时间:2017-08-31 16:04:27      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:tle   input   title   bsp   cookies   会话   json   draft   like   

#coding:utf-8

import requests,json,re

‘‘‘
session关联接口,第一步访问登录接口,headers中要有cookie,不然会登录失败,
登录成功后,添加随笔保存为草稿,第三步判断保存草稿成功
‘‘‘ 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", "Content-Type":"application/json; charset=UTF-8", "Accept":"application/json, text/javascript, */*; q=0.01", "Accept-Encoding":"gzip, deflate, br", "Accept-Language":"zh-CN,zh;q=0.8", "X-Requested-With":"XMLHttpRequest", "Cookie":"AspxAutoDetectCookieSupport=1; SERVERID=227b087667da6f8e99a1165002db93f6|1504147566|1504146209" } payload = {"input1":"SZqepch8gyaT4siZXmJTawyDvPs0mYiYTarlAj6ZViwAG5K6mC2gfT2/kwqzaLSF4HrnyajRPa6gXIWUtRBTW5SC+hvUmETyNrkcUwToEHqjRoAmmq8+SFaK4v51KNVnwyk9xhiXv+VEe2gkdn+Wu7dAIoBdwEXNHmo4J89T8K0=", "input2":"WypnynD3C5ibcgFuQTZImpQvlL183850joTwgYvjwKa7hFpZq/P0Pi6MamY8ezN29oBa1n+9FAxCM4w4HxlS+X0CJmeAAkqvWGIfl3kussg/BeFPjl+UOhwtc8EGJVojs0f0wdevAs023Pr+4mVWSKBgPwQWfCwVo8a6EsaJ1qI=", "remember":False} payload = json.dumps(payload)
#session会话保持,重点关注
s
= requests.session() r = s.post(url,data=payload,headers=headers,verify=False) print(r.json()) #保存草稿箱 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(rvalue="(.+?)" maxlength,r2.content.decode(encoding=utf-8)) print(t[0]) if t[0] == 这是我的标题:上海-悠悠: print(True) else: print(False)

 

session关联接口

标签:tle   input   title   bsp   cookies   会话   json   draft   like   

原文地址:http://www.cnblogs.com/yrxns/p/7458204.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!