热门在python中拆分许多行的请求?

时间:2017-09-08 21:00:48

标签: python python-3.x

代码

import requests

url = "http://store.place.com.br/api/oms/pvt/orders"

headers = {

    'accept': "application/json",
    'content-type': "application/json",
    'x-vtex-api-apptoken': "{{VTEX-API-TOKEN}}",
    'x-vtex-api-appkey': "{{VTEX-API-KEY}}"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

代码二

url = "http://store.place.com.br/api/oms/pvt/orders/oderId"

headers = {

    'accept': "application/json",
    'content-type': "application/json",
    'x-vtex-api-apptoken': "{{VTEX-API-TOKEN}}",
    'x-vtex-api-appkey': "{{VTEX-API-KEY}}"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

我的结果是:

{" list":[{" orderId":" BWW-Lojas_Americanas-265033423001",... {"订单ID":" BWW-Lojas_Americanas-265032819901""序列":" 506927""市场

如何在多行中拆分每个列表?之后,我想将它们保存在不同的files.txt

1 个答案:

答案 0 :(得分:0)

您应该使用JSON将回复读作requests.request(...).json()。然后,您可以处理列表中的每个订单。

以下是一个例子:

response = requests.request("GET", url, headers=headers).json()

for order in response['list']:
    # Process each order
    # ...