【问题标题】:How to Iterate over @odata.nextLink from API response and append the data to a file?如何从 API 响应迭代 @odata.nextLink 并将数据附加到文件?
【发布时间】:2022-11-16 11:13:29
【问题描述】:

我如何使下面的工作代码遍历数据 ["@odata.nextLink"] 并将数据 ["value"] 附加到 sample.json 文件?

import requests 
import json
import datetime


def get_data():
    bearerAccessToken = '*************'
    now = datetime.datetime.now()-datetime.timedelta(days=10)
    dt_string = now.strftime("%Y-%m-%dT%H:%M:%S-04:00")
    print(dt_string)
    resourceUrl = "https://retsapi.raprets.com/CIN/RESO/OData/Property?Class=Residential&$count=true"
    query_params = {"$filter":"ModificationTimestamp ge "+dt_string}
    print(query_params)

    r = requests.get(resourceUrl, params=query_params, headers={'Authorization' : 'Bearer '+ bearerAccessToken})

    data = r.json()

    with open("sample.json", "w") as outfile:
        json.dump(data["value"], outfile)

    print(data["@odata.nextLink"])



get_data()

【问题讨论】:

    标签: python pagination iteration get-request next-link


    【解决方案1】:

    你能找到解决这个问题的方法吗?

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 2020-06-07
    • 2021-05-05
    • 2021-07-01
    • 2019-08-17
    • 1970-01-01
    • 2021-01-19
    相关资源
    最近更新 更多