我试图从json instagram解析likes count,comments count,video\u views comment,使用likes和comments没有问题,但我不明白如何获取video_views,因为likes和comments计数与like和comments对象有相应的联系,但video_views没有。每次我通过视频查看keyror
import urllib.request
import simplejson as json
import urllib.request
url = 'https://www.instagram.com/mcgregor_best/media/'
count = int
response = urllib.request.urlopen(url).read().decode('UTF-8')
json_obj = json.loads(response)
for item in json_obj['items']:
print(item['likes']['count'])
for item in json_obj['items']:
print(item['comments']['count'])
for item in json_obj['items']:
print(item['video_views'])
并不是每个项目都有一个json中的video\u views键。将
print(item['video_views'])
替换为:如果视频作为一个键存在,这将为您提供video_views的值,否则将不提供任何值。在
相关问题 更多 >
编程相关推荐