我就废话不多说了,大家还是直接看代码吧!

import requests
import json

raw = {}

headers中添加上content-type这个参数,指定为json格式

headers = {‘Content-Type': ‘application/json'}

post的时候,将data字典形式的参数用json包转换成json格式。

response = requests.post(url=‘XXXX',
headers=headers, data=json.dumps(raw))

返回信息

print(response.text)

返回响应头

print(response.status_code)

补充知识:python3使用requests发送post请求,对接口返回的数据进行处理,最后塞入list,保存到本地的excel中

我就废话不多说了,大家还是直接看代码吧!

#coding:utf-8

import http.cookiejar
import json
from urllib import parse,request
import requests
from openpyxl import Workbook
import datetime

name = 'tarcuper'
allowed_domains = ['*']
start_urls1 = 'https://www.tracup.com/api/issues/view'
start_urls2 = 'https://www.tracup.com/api/issues/getTrendList'

cookies = {
  "acw_tc": "78197306155549842936beitidaile9532fb18575fad1fc268ee",
  "_ga": "GA1.2.1414148155.1555498434",
  "PHPSESSID": "q7hj5m5neitidaile95efop7eee37ki",
  "_gid": "GA1.2.1742874168.1557716531",
  "pgyx2_session": "wN99ZYREthkeqaL92z0TyFP1W7u3WMIsN8MhrIxaP7m4pHYCERP8p9X7RlR4p3zIhkID%2B2SpEj%2BWQ2L%2FVZlV7DqvMQHvZAEDNMtr88KWpCxMB7U%2FCUasbRfR7HA6GtXfsezWclbCwkHNVanq0Pd2uh5U051O1gh3ducUjpugaydrcKG65bg7ae%2BsVx4pgqUyHB00%2F%2Fvh3cPGTbTNHdWIolrA7QRhH6K5OWQlfgIH1ugvnd69LYeitidaile95WyxIJZC4XtUOJA7YYkTQReN2P92E%2BrwxCcRJCHWm6vs9Jw1IrgdFo%2BXzG4ylpZFCtFGK0RmgX%2FR3n9Cc%2FMdE1AsMG58xCDYVbt9Bz4Fe53CR1ujRMX9MWWeHyZt5vcbRT%2FIQhcapZREpR7qgsdQ0ZAfPFvZGa1RPtSFxqrFN%2BGUhPhLy%2BNu0fK4n%2F99ZWiG7rrxk%2BPybM2gQZ2JZ5KYXvAGiQ%2Bq4%3D"
}

headers = {
  "Host": "www.tracup.com",
  "Connection": "keep-alive",
  "Cache-Control": "no-cache",
  "Pragma": "no-cache",
  "If-Modified-Since": "0",
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36",
  "Accept": "*/*",
  "Referer": "https://www.tracup.com/cloud/",
  "Accept-Encoding": "gzip, deflate, br",
  "Accept-Language": "zh-CN,zh;q=0.9",
}

def request2():
  req2 = requests.post(url=start_urls2, data=data, headers=headers, cookies=cookies)
  res2 = req2.text
  res2 = json.loads(res2)
  bbb = (res2['data'])
  # print(bbb)
  # print('上面bbb,下面cccc')
  ccc = (bbb['list'])
  # print(ccc)
  for var in ccc:
    iac_created = var.get('iac_created')
    log = var.get('log')
    # print(log)
    # print(iac_created)
    if log == "修改状态为 已解决":
      return iac_created

wb = Workbook()
ws = wb.create_sheet("che")
for i in range(1,500):
  data = {
    "pKey":"916338276d07f3c1cacc662b2afa93c2",
    "iNo":str(i),
    }
  req = requests.post(url=start_urls1, data=data, headers=headers, cookies=cookies)
  res = req.text
  res = json.loads(res)
  aaa = (res['data'])
  _alist = []
  j = 0

  try:
    iac_created = request2()
    i_no = aaa['i_no']
    author = aaa['author']
    assigner = aaa['assigner']
    i_created = aaa['i_created']
    i_updated = aaa['i_updated']
    i_status = aaa['i_status']
  except:
    pass
  if i_status == 'a3f47781286ee2ba2bbefbebd0bea5bc' and iac_created != None:
      _alist.append(i_no)
      _alist.append(author)
      _alist.append(assigner)
      _alist.append(i_created)
      _alist.append(iac_created)
      d1 = datetime.datetime.strptime(i_created, '%Y-%m-%d %H:%M')
      d2 = datetime.datetime.strptime(iac_created, '%Y-%m-%d %H:%M:%S')
      d = d2-d1
      days = d.days
      delta = d.seconds
      h = round(days*24+delta/3600)
      _alist.append(h)
      print(_alist)
      ws.append(_alist)
  wb.save("aaa.xlsx")

以上这篇python3发送request请求及查看返回结果实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。