-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.py
59 lines (45 loc) · 1.42 KB
/
scraper.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
import numpy as np
import pandas as pd
import instaloader
import tqdm
#! pip install instaloader
data = pd.DataFrame(columns=['username','image_url', 'following', 'followers', 'date', 'time', 'likes', 'caption'])
info = []
def scraper(hashtag):
L = instaloader.Instaloader()
posts = L.get_hashtag_posts(hashtag)
likes = []
caption = []
date = []
time = []
image_url = []
username = []
following = []
followers = []
count = 0
for i in tqdm(posts):
if i.is_video == False:
likes.append(i.likes)
k = str(i.caption)
k = k.replace('\n', " ")
caption.append(k)
date.append(i.date.strftime("%d-%m-%Y"))
time.append(i.date.strftime("%H:%M:%S"))
image_url.append(i.url)
profile = instaloader.Profile.from_username(L.context, i.owner_username)
username.append(i.owner_username)
following.append(profile.followees)
followers.append(profile.followers)
count+=1
if count == 1000 :
break
user_data = pd.DataFrame(list(zip(username, image_url, following, followers, date, time, likes, caption)),
columns=['username','image_url', 'following', 'followers', 'date', 'time', 'likes', 'caption'])
global data
data = data.append(user_data, ignore_index=True, sort=False)
print(data.shape)
info.append([hashtag, len(likes)])
print(info)
scraper('modichod')
data
data.to_excel('data.xlsx', index=False)