【发布时间】:2017-03-04 02:25:50
【问题描述】:
如何获得所有喜欢某张图片的用户?我看到在有 76 个赞的特定照片的page_info 中,有u'end_cursor': None 我无法使用它来获得其余的赞。同样如 JSON 所示,仅显示了 10 个用户 ID。
u'page_info': {u'end_cursor': None,
u'has_next_page': False,
u'has_previous_page': False,
u'start_cursor': None}},
http://pastebin.com/AZUQBvrF
我在遍历 Instagram 用户的其他页面时遇到了类似的问题,我使用以下代码解决了这个问题。但是,我不确定end_cursor=None 时如何处理这个问题?请提出解决方案和指导。
99 while data["user"]["media"]["page_info"]["has_next_page"]:
100 end_cursors.append(data["user"]["media"]["page_info"]["end_cursor"])
101 data = json.loads(requests.get('https://www.instagram.com/ducks_love_sun/?__a=1&max_id={}'.format(end_cursors[-1])).text)
102 #pprint(data)
103
104 for i in range(len(json_response["user"]["media"]["nodes"])):
105 count = count + 1
106 print json_response["user"]["media"]["nodes"][i]["likes"]["count"], count
在一张图片中我们可以看到:
u'likes': {u'count': 76,
u'nodes': [{u'user':
但是 json 中只显示了 10 个节点!
请随意查看以下示例: https://www.instagram.com/p/BRG1WiEA1yM/?__a=1
我尝试了以下但仍然得到10个节点的内容:
pprint(img_response["media"]["likes"].items())
结果显示在这里:http://pastebin.com/7rPLqnUS
**更新:正如您在此 pastebin 中看到的,具有许多 cmets 的照片的 json 具有 end_cursor,我可以使用它来遍历所有 cmets:
http://pastebin.com/wbeZAt8y
虽然似乎没有喜欢的光标!
标签: python json web-scraping scrapy instagram