-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.py
67 lines (55 loc) · 2.06 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
60
61
62
63
64
65
66
67
try:
import requests
from bs4 import BeautifulSoup as bs
except:
print("<Install the module requests, bs4>")
commands = """
pip install requests bs4
"""
print(":::Commands:::")
print(commands)
exit()
github_user = input("Input github username: ")
url = f"https://github.com/{github_user.strip()}"
response = requests.get(url)
if response.status_code == 200:
print("\n<User Found>")
print("<Loading Information>")
# html parse all the content
try:
soup = bs(response.content, 'html.parser')
user_info = soup.title.text
profile_image = soup.find('img', {"alt": "Avatar"})['src']
user_name = soup.find('span', {"itemprop": "name"}).text.strip()
raw_data = soup.find_all(
"a", {"class": "Link--secondary no-underline no-wrap"})
followers = raw_data[0].text.strip().split()[0]
following = raw_data[1].text.strip().split()[0]
repositories = soup.find('span', {'class': 'Counter'}).text
additional_data = soup.find_all(
'a', {"class": "Link--primary", "rel": "nofollow me"})
information = f"""
::::: Information :::::
{user_info}
Username : {user_name}
Followers : {followers}
Following : {following}
Repositories: {repositories}
:::: Additional Information And Links ::::"""
print(information)
print("Profile image :: "+profile_image)
# new_data = soup.find_all('div', {'class': 'p-note user-profile-bio mb-3 js-user-profile-bio f4'})[0].\
# find_all('a', {'class': 'user-mention'})
# for info in new_data:
# print(info.text)
data = soup.find_all(
'div', {'class': 'p-note user-profile-bio mb-3 js-user-profile-bio f4'})
print(data[0].text)
links = soup.find_all('a', {'rel': 'nofollow'})
for link in links:
print(link.text, end=" :: ")
print(link['href'])
except:
print(f'<{github_user} doesn\'t have any public repositories yet>')
else:
print(f"<No Username with {github_user}>")