-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRating_Tracker.py
63 lines (44 loc) · 1.93 KB
/
Rating_Tracker.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
# Online Coding Platform Rating Tracker
'''
Scrapes the Online Coding Platforms like Codechef, Codeforces, HackerEarth and SPOJ with the help of given URLs and
extracts the rating for a given user and prints the rating.
'''
import bs4 as bs
import requests
# URLs of Coding Platforms
cc_url = 'https://www.codechef.com/users/ramm_y2k'
cf_url = 'http://codeforces.com/profile/iamram'
he_url = 'https://www.hackerearth.com/users/pagelets/ram13/coding-data/'
spoj_url = 'https://www.spoj.com/users/iam_ram/'
# Codeforces Scrapping
cf_response = requests.get(cf_url)
cf_html = cf_response.text
cf_soup = bs.BeautifulSoup(cf_html, "lxml")
# Extracting the rating and the position
cf_rating = cf_soup.find('div', class_='info').find('ul').find('li').find('span').text
cf_position = cf_soup.find('div', class_='user-rank').find('span').text.strip()
# print('Codeforces Rating: {} ({})'.format(cf_rating, cf_position))
# Codechef Scrapping
cc_response = requests.get(cc_url)
cc_html = cc_response.text
cc_soup = bs.BeautifulSoup(cc_html, "lxml")
# Extracting the rating and stars
cc_rating = cc_soup.find('div', class_='rating-number').text
cc_stars = cc_soup.find('div', class_='rating-star').text
# print('CodeChef Rating: {} ({})'.format(cc_rating, cc_stars))
# HackerEarth Scrapping
he_response = requests.get(he_url)
he_html = he_response.text
he_soup = bs.BeautifulSoup(he_html, "lxml")
# Extracting the Rating
he_rating = he_soup.find('a', class_='dark weight-700').text
# print('Hacker Earth Rating: {}'.format(he_rating))
# SPOJ Scrapping
spoj_response = requests.get(spoj_url)
spoj_html = spoj_response.text
spoj_soup = bs.BeautifulSoup(spoj_html, "lxml")
temp = spoj_soup.find('div', class_='col-md-3')
# Either of the below will work - The Rank is present in the third <p> tag.
# spoj_rank = temp.find('p').find_next('p').find_next('p').text.strip()
spoj_rank = temp.select_one("p:nth-of-type(3)").text.strip()
# print('SPOJ {}'.format(spoj_rank))