我从几个小时以来一直在尝试从我的 Pocket API 列表检索中获取数据帧。
但是我的代码最终只在一行中添加了所有内容,这不是我想要的。
我尝试了很多,但没有找到错误。
我的代码如下所示:
import json
import pandas as pd
from pandas.io.json import json_normalize
from flatten_json import flatten
import collections
import requests
from urllib.parse import urlencode
from urllib.request import Request, urlopen
# GET request for data in JSON format
parameters = {
'consumer_key' : '9...9',
'access_token' : 'c...b',
'detailType' : 'complete',
'count' : '10'
}
response = requests.get('https://getpocket.com/v3/get', params=parameters)
json_string = response.json()
df=pd.json_normalize(json_string)
print(df)
结果如下所示:
status complete error ... list.3483242700.domain_metadata.greyscale_logo list.3483242700.listen_duration_estimate search_meta.search_type
0 1 1 None ... https://logo.clearbit.com/washingtonpost.com?s... 0 normal
源 JSON resonse.text 如下所示:
{"status":1,"complete":1,"list":{"237938806":{"item_id":"237938806","resolved_id":"237938806","given_url":"https:\/\/getpocket.com\/developer\/docs\/v3\/retrieve","given_title":"Pocket Developer Program: Pocket API: Retrieve","favorite":"0"
....
washpost.s3.amazonaws.com\/public\/SMWO67R4BAI6XKWZRFMSE4UAYQ.jpg&w=1440","domain_metadata":{"name":"The Washington Post","logo":"https:\/\/logo.clearbit.com\/washingtonpost.com?size=800","greyscale_logo":"https:\/\/logo.clearbit.com\/washingtonpost.com?size=800&greyscale=true"},"listen_duration_estimate":0}},"error":null,"search_meta":{"search_type":"normal"},"since":1638029019}