-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile-scrapper.py
60 lines (48 loc) · 1.37 KB
/
profile-scrapper.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Scraps images from instagram of a specifc user and saves them in a folder
import requests
import os
import time
import random
# get images from user profile
def get_images(username):
url = "https://www.instagram.com/" + username + "/"
print(url)
# get the webpage
response = requests.get(url)
# parse the html
html = response.text
# find the image url
start = html.find("\"display_url\":\"") + len("\"display_url\":\"")
end = html.find("\",\"is_video")
image_url = html[start:end]
# Downloads the image
print(image_url)
response = requests.get(image_url)
image = response.content
# Saves the image
with open(username + ".jpg", "wb") as f:
f.write(image)
time.sleep(random.randint(1, 3))
return image_url
# Gets the user names
def get_users():
# gets the tags
url = "https://www.instagram.com/explore/tags/"
response = requests.get(url)
html = response.text
start = html.find("<meta property=\"og:description\"") + len("<meta property=\"og:description\"")
end = html.find("\"/>")
users = html[start:end]
users = users.split(",")
return users
# main
def main():
# get the tags
users = get_users()
# get the images
for user in users:
get_images(user)
if __name__ == "__main__":
main()
# end of file
#!/usr/bin/env python3