python user in instagram api

Solutions on MaxInterview for python user in instagram api by the best coders in the world

showing results for - "python user in instagram api"
Valerio
02 Jan 2020
1# importing libraries 
2from bs4 import BeautifulSoup 
3import requests 
4
5# instagram URL 
6URL = "https://www.instagram.com/{}/"
7
8# parse function 
9def parse_data(s): 
10	
11	# creating a dictionary 
12	data = {} 
13	
14	# splittting the content 
15	# then taking the first part 
16	s = s.split("-")[0] 
17	
18	# again splitting the content 
19	s = s.split(" ") 
20	
21	# assigning the values 
22	data['Followers'] = s[0] 
23	data['Following'] = s[2] 
24	data['Posts'] = s[4] 
25	
26	# returning the dictionary 
27	return data 
28
29# scrape function 
30def scrape_data(username): 
31	
32	# getting the request from url 
33	r = requests.get(URL.format(username)) 
34	
35	# converting the text 
36	s = BeautifulSoup(r.text, "html.parser") 
37	
38	# finding meta info 
39	meta = s.find("meta", property ="og:description") 
40	
41	# calling parse method 
42	return parse_data(meta.attrs['content']) 
43
44# main function 
45if __name__=="__main__": 
46	
47	# user name 
48	username = input('Input username: ')
49	
50	# calling scrape function 
51	data = scrape_data(username) 
52	
53	# printing the info 
54	print(data) 
55