-
Notifications
You must be signed in to change notification settings - Fork 2
/
codeforces.py
35 lines (26 loc) · 1.17 KB
/
codeforces.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
import requests
from bs4 import BeautifulSoup, NavigableString
class Codeforces():
url = ""
problems_url = ""
def __init__(self):
self.url = "https://codeforces.com/submissions"
self.submission_url = "https://codeforces.com/submissions/"
def is_valid_user(self, username):
url = self.submission_url + username
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
articles = soup.find_all('span', attrs={'submissionverdict': 'OK'})
return len(articles) > 0
def get_user_problems(self, username):
url = self.submission_url + username
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
articles = soup.find_all('span', attrs={'submissionverdict': 'OK'})
problems = [str((row.parent.parent.find_all('a')[2]).text).strip() for row in articles]
urls = [str((row.parent.parent.find_all('a')[2]['href'])).strip() for row in articles]
urls = [str(self.url + url) for url in urls]
return problems, urls
if __name__ == "__main__":
cf = Codeforces()
cf.get_user_problems("ishpreet")