-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscraper.py
More file actions
40 lines (29 loc) · 902 Bytes
/
scraper.py
File metadata and controls
40 lines (29 loc) · 902 Bytes
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
from instagrapi import Client
import pandas as pd
import time
import os
USERNAME = os.getenv("IG_USERNAME")
PASSWORD = os.getenv("IG_PASSWORD")
client = Client()
client.login(USERNAME, PASSWORD)
with open("profiles.txt", "r") as f:
profiles = [line.strip() for line in f]
rows = []
for username in profiles:
try:
print(f"Fetching {username}")
user = client.user_info_by_username(username)
rows.append({
"username": user.username,
"full_name": user.full_name,
"biography": user.biography,
"followers": user.follower_count,
"following": user.following_count,
"profile_url": f"https://instagram.com/{user.username}"
})
time.sleep(5)
except Exception as e:
print(e)
df = pd.DataFrame(rows)
df.to_excel("output/instagram_profiles.xlsx", index=False)
print("Done.")