Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from InstagramAPI import InstagramAPI
- import time
- from datetime import datetime
- time_start = time.time()
- login = ""
- password = ""
- user_id = '5612607660'
- # stop conditions, the script will end when first of them will be true
- count = 1000
- API = InstagramAPI(login, password)
- API.login()
- user_feed_list = API.getTotalUserFeed(user_id)
- # print(user_feed_list[0])
- for i in user_feed_list:
- has_more_comments = True
- max_id = ''
- comments = []
- id_media = i['id']
- while has_more_comments:
- _ = API.getMediaComments(id_media, max_id=max_id)
- # comments' page come from older to newer, lets preserve desc order in full list
- for c in reversed(API.LastJson['comments']):
- comments.append(c)
- has_more_comments = API.LastJson.get('has_more_comments', False)
- # evaluate stop conditions
- if count and len(comments) >= count:
- comments = comments[:count]
- # stop loop
- has_more_comments = False
- print("stopped by count")
- # next page
- if has_more_comments:
- max_id = API.LastJson.get('next_max_id', '')
- time.sleep(2)
- print(comments)
- has_more_comments = True
- max_id = ''
- comments = []
- time_end = time.time()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement