Python 3.x Python3.8-json并更新分页中的值
我一直在研究一些API摄取,不知道如何更新分页页面。整个集合的默认值为50,我想将其更新为总数的一半 这是我的密码:Python 3.x Python3.8-json并更新分页中的值,python-3.x,Python 3.x,我一直在研究一些API摄取,不知道如何更新分页页面。整个集合的默认值为50,我想将其更新为总数的一半 这是我的密码: import requests import pandas as pd import json import time import os from datetime import datetime #STEP 1 set up params with api key (it defaults to limit:
import requests
import pandas as pd
import json
import time
import os
from datetime import datetime
#STEP 1 set up params with api key (it defaults to limit:50). this step is only to read the total.
params = {
'access_key': 'API_KEY'
}
url = 'https://some_website'
api_result = requests.get(url, params)
api_response = api_result.json()
#read the total and set the limit = limit /10
get_total = (api_response.get('pagination'))
total_entries = get_total['total'] / 10
print(total_entries)
#STEP 2 use the total_entries for data ingest
params2 = {
'access_key': 'API_KEY',
'limit': total_entries
}
print(params2)
api_result2 = requests.get(url, params2)
api_response2 = api_result2.json()
data = api_response2['data']
df = pd.json_normalize(data)
但它默认回到50。任何人都知道这件事