-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeforces.py
26 lines (25 loc) · 866 Bytes
/
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
import urllib.request
import simplejson as JSON
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
def codeforces_web_scraping(username):
base="http://codeforces.com/api/user.info?handles="
profile=base+username
try:
request_url = urllib.request.urlopen(profile)
request=request_url.read().decode("utf-8")
data=JSON.loads(request)
return 1,data['result'][0]
except urllib.error.HTTPError as err:
if err.code == 404:
print("Page not found!")
return 0,"Page not found!"
elif err.code == 403:
print("Access denied!")
return 0,"Access denied!"
else:
print("Something happened! Error code", err.code)
return 0,username+" not found on "+"codeforces!"
except urllib.error.URLError as err:
print("Some other error happened:", err.reason)
return 0,"Some other error happened:/check your internet connectivity"