-
Notifications
You must be signed in to change notification settings - Fork 1
/
igScrapper.py
60 lines (54 loc) · 1.45 KB
/
igScrapper.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
"""
Project Name: Instagram Profile Scrapper
"""
# Import Library
from os import system
from bs4 import BeautifulSoup
import requests
import platform
# Check the OS
def checkOS():
if platform.system() == "Linux":
sys = "clear"
elif platform.system() == "Windows":
sys = "cls"
else:
print("OS Not supported")
exit()
return sys
# Get IG username from user input
print("--------------------------------------------")
print("Input example : galihsptr320")
print("--------------------------------------------")
def getInput():
username = ""
username = input("Input instagram username here: ")
if username == "":
system(checkOS())
print("Please input instagram username")
getInput()
return username
# Data Parser
def parse(scrap):
result = {}
scrap = scrap.split("-")[0]
scrap = scrap.split(" ")
result['Followers'] = scrap[0]
result['Following'] = scrap[2]
result['Posts'] = scrap[4]
return result
# Scrapping data
def scrap_data(username):
req = requests.get("https://instagram.com/" + username)
res = BeautifulSoup(req.text, "html.parser")
meta = res.find("meta", property="og:description")
return parse(meta.attrs['content'])
# Main Function
if __name__ == "__main__":
try:
data = scrap_data(getInput())
print("Result:")
print(data)
except KeyboardInterrupt:
print("\nCancelled by user")
exit()