• python requests接口测试 -----博客园串接口


     1 #-*- coding:utf-8 -*-
     2 __author__ = "carry"
     3 import requests
     4 import re
     5 # 禁用安全请求警告
     6 from requests.packages.urllib3.exceptions import InsecureRequestWarning
     7 requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
     8 
     9 s = requests.session()
    10 
    11 '''第一个接口--------------登录接口'''
    12 url1 = "https://passport.cnblogs.com/user/signin"
    13 header = {#这里放的headers
    14     "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
    15     "Accept-Encoding":"gzip, deflate, br",
    16     "Accept-Language":"zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",
    17     "X-Requested-With":"XMLHttpRequest",
    18     "Content-Type":"application/json; charset=utf-8",
    19     "Cookie":"AspxAutoDetectCookieSupport=1; SERVERID=227b087667da6f8e99a1165002db93f6|1505215478|1505215339"
    20 }
    21 json_data1 = {"input1":"B45eEa7p/zb2jqJo+ihKz7FeVDXtS380b5w8aTGO1F6uIw7icjMj1YfMFzfnq1C2qsp0boCptBgVT8arrs/E6kpc9/jccd6fzXaJjXwZ0Sf3hxoS08yIPa9KNshl6iK+3JwemykcFRMcvF6J2Vo=",
    22              "input2":"x4bkPbfodgUamTPlmz/HOQAU7nsf1kFyXhinHEak49GJMu0FtGLBZg6qlV/NqRh2pI+LKWmqR513h6Ktz4eLA8ThtCxLFs9NvkMkPCn91mqJs29V3FQWPBtVWmRvyn9gEtFDJlKqSHb7tPer57bvRdE=",
    23              "remember":False}
    24 res1 = s.post(url1, headers=header, json=json_data1, verify=False)
    25 print (res1.json())
    26 
    27 '''第二个接口--------------存为草稿接口'''
    28 url2 = "https://i.cnblogs.com/EditPosts.aspx?opt=1"
    29 json_data2 = {"__VIEWSTATE": "",
    30      "__VIEWSTATEGENERATOR": "FE27D343",
    31      "Editor$Edit$txbTitle": "我是杀手2号",
    32      "Editor$Edit$EditorBody": "<p>%s</p>" % "我是杀手2号",
    33      "Editor$Edit$Advanced$ckbPublished": "on",
    34      "Editor$Edit$Advanced$chkDisplayHomePage": "on",
    35      "Editor$Edit$Advanced$chkComments": "on",
    36      "Editor$Edit$Advanced$chkMainSyndication": "on",
    37      "Editor$Edit$lkbDraft": "存为草稿", }
    38 res2 = s.post(url2, data=json_data2, verify=False)
    39 print(res2.url)
    40 '''这个地方是提取postid,使用正则表达式'''
    41 postid = re.findall(r"postid=(.+?)&", res2.url)
    42 print (postid)
    43 print (postid[0])
    44 
    45 '''第三个接口--------------删除草稿接口'''
    46 json_data3 = {"postId": postid[0]}
    47 r3 = "https://i.cnblogs.com/post/delete"
    48 res3 = s.post(r3, json=json_data3, verify=False)
    49 print(res3.json()["isSuccess"])
  • 相关阅读:
    分解质因数算法
    js 的 Math 对象
    字符串操作
    简化求质数算法
    数值类型小数点后是否可以接零问题
    新博第一篇,思考的重要性与求质数算法
    一、制作屏幕录像
    四、同步线程
    常见问题
    jni数据处理
  • 原文地址:https://www.cnblogs.com/lxs1314/p/7512472.html
Copyright © 2020-2023  润新知