-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.py
80 lines (66 loc) · 2.86 KB
/
github.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import requests
from bs4 import BeautifulSoup
from concurrent.futures import ThreadPoolExecutor
def scrape_github_profile(username):
url = f"https://www.github.com/{username}"
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
username_element = soup.find("span", class_="p-nickname vcard-username d-block")
username = username_element.get_text(strip=True) if username_element else None
fullname_element = soup.find("span", class_="p-name vcard-fullname d-block overflow-hidden")
fullname = fullname_element.get_text(strip=True) if fullname_element else None
location_element = soup.find("li", class_="vcard-detail pt-1 hide-sm hide-md", itemprop="homeLocation")
location = location_element.find("span", class_="p-label").get_text(strip=True) if location_element else None
organization_element = soup.find("li", class_="vcard-detail pt-1 hide-sm hide-md", itemprop="worksFor")
organization = organization_element.find("span", class_="p-org").get_text(strip=True) if organization_element else None
social_links = soup.find_all("li", itemprop="social")
social_links_list = [link.find("a", class_="Link--primary").get("href") for link in social_links] if social_links else None
timezone_element = soup.find("li", class_="vcard-detail pt-1 hide-sm hide-md", itemprop="localTime")
timezone = timezone_element.find("span", class_="p-label").get_text(strip=True) if timezone_element else None
followers_element = soup.find("span", class_="text-bold color-fg-default")
followers = followers_element.get_text(strip=True) if followers_element else None
following_element = soup.find("a", class_="Link--secondary no-underline no-wrap")
following = following_element.find("span").get_text(strip=True) if following_element else None
return {
"Username": username,
"Full Name": fullname,
"Location": location,
"Organization": organization,
"Social Links": social_links_list,
"Time Zone": timezone,
"Followers": followers,
"Following": following
}
def scrape_profiles(usernames):
with ThreadPoolExecutor() as executor:
results = executor.map(scrape_github_profile, usernames)
for username, result in zip(usernames, results):
print("Scraping profile for", username)
for key, value in result.items():
print(key + ":", value)
print('----------------------------------------')
# List of usernames to scrape
usernames = [
"twinstar",
"JLaurey",
"octocat",
"defunkt",
"mojombo",
"pengwynn",
"pjhyett",
"schacon",
"kevinclark",
"technoweenie",
"atmos",
"jekyll",
"benbalter",
"holman",
"dhh",
"mojombo",
"tpope",
"sindresorhus",
"addyosmani",
"taylorotwell"
]
# Scrape profiles for each username
scrape_profiles(usernames)