-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_images.py
More file actions
30 lines (23 loc) · 849 Bytes
/
fetch_images.py
File metadata and controls
30 lines (23 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import requests
import os
session_token = os.getenv('SESSION')
baseUrl = 'https://www.instagram.com/'
topsearch = 'web/search/topsearch/?context=blended&query=/'
images = 'explore/locations/'
def get_images(city):
url = baseUrl + topsearch
querystring = {"context": "blended", "query": city}
headers = {'cache-control': 'no-cache'}
response = requests.request(
"GET", url, headers=headers, params=querystring)
cityId = response.json()['places'][0]['place']['location']['pk']
url = baseUrl + images + str(cityId) + "/?__a=1"
jar = requests.cookies.RequestsCookieJar()
jar.set('sessionid', session_token)
payload = ""
headers = {
'cache-control': "no-cache"
}
response = requests.request(
"GET", url, data=payload, headers=headers, cookies=jar)
return response.json()