-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile_data.py
47 lines (39 loc) · 1.54 KB
/
profile_data.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
import instaloader
import re
# Function to retrieve profile information
def retrieve_profile_info(username: str):
# Create an instance of Instaloader
loader = instaloader.Instaloader()
try:
# Load the profile
profile = instaloader.Profile.from_username(loader.context, username)
# Access profile details
biography = profile.biography
# Regex patterns for emails and phone numbers
email_pattern = r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
phone_pattern = r'\+?\d[\d -]{8,12}\d'
# Find all matches
emails = re.findall(email_pattern, biography)
phone_numbers = re.findall(phone_pattern, biography)
# Access profile details
profile_info = {
'user_info':{
'uniqueID': profile.userid,
'Username': profile.username,
'Full_Name': profile.full_name,
'Followers': profile.followers,
'Following': profile.followees,
'Bio': profile.biography,
'Bio_hashtags': profile.biography_hashtags,
'Bio_mentions': profile.biography_mentions,
'Number_of_Posts': profile.mediacount,
'External_URL': profile.external_url,
},
'Contact_info': {
'Emails': emails,
'Phone_numbers': phone_numbers
}
}
return profile_info
except instaloader.exceptions.ProfileNotExistsException:
return None