-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathInstgramProfile.py
More file actions
52 lines (46 loc) · 1.57 KB
/
InstgramProfile.py
File metadata and controls
52 lines (46 loc) · 1.57 KB
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
import requests
from lxml import html
import re
import sys
def main(username):
"""main function accept instagram username
return an dictionary object containging profile deatils
"""
url = "https://www.instagram.com/{}/?hl=en".format(username)
page = requests.get(url)
tree = html.fromstring(page.content)
data = tree.xpath('//meta[starts-with(@name,"description")]/@content')
if data:
data = tree.xpath('//meta[starts-with(@name,"description")]/@content')
data = data[0].split(", ")
followers = data[0][:-9].strip()
following = data[1][:-9].strip()
posts = re.findall(r"\d+[,]*", data[2])[0]
name = re.findall(r'name":"\w*[\s]+\w*"', page.text)[-1][7:-1]
aboutinfo = re.findall(r'"description":"([^"]+)"', page.text)[0]
instagram_profile = {
"success": True,
"profile": {
"name": name,
"profileurl": url,
"username": username,
"followers": followers,
"following": following,
"posts": posts,
"aboutinfo": aboutinfo,
},
}
else:
instagram_profile = {"success": False, "profile": {}}
return instagram_profile
# python InstgramProfile.py username
if __name__ == "__main__":
"""driver code"""
if len(sys.argv) == 2:
output = main(sys.argv[-1])
print(output)
else:
print(
"=========>Invalid paramaters Valid Command is<=========== \
\npython InstagramProfile.py username"
)