Created
February 4, 2019 23:53
-
-
Save tikseniia/9ae5e00262a0460423b4391c23cf9b92 to your computer and use it in GitHub Desktop.
Get post location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open('posts.json', 'r') as f: | |
arr = json.loads(f.read()) # load json data from previous step | |
locations = [] | |
for item in arr: | |
shortcode = item['shortcode'] | |
url = "https://www.instagram.com/p/{0}/?__a=1".format(shortcode) | |
r = requests.get(url) | |
data = json.loads(r.text) | |
try: | |
location = data['graphql']['shortcode_media']['location']['name'] # get location for a post | |
except: | |
location = '' # if location is NULL | |
locations.append({'shortcode': shortcode, 'location': location}) | |
with open('locations.json', 'w') as outfile: | |
json.dump(locations, outfile) # save to json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment