forked from Python-World/python-mini-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (53 loc) · 1.88 KB
/
main.py
File metadata and controls
62 lines (53 loc) · 1.88 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
53
54
55
56
57
58
59
60
61
62
import requests
from lxml import html
import re
import sys
import pprint
from profilepic import pp_download
def banner():
print('\t""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""')
print('\t InstgramProfile data graber ')
print('\t""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""')
def main(username):
banner()
'''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":"([^"]+)"', page.text)[0]
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 main.py username
if __name__ == "__main__":
if len(sys.argv) == 2:
output = main(sys.argv[-1])
pp_download(sys.argv[-1])
pprint.pprint(output)
else:
print('Invalid paramaters Valid Command \n\tUsage : python main.py username')