-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtry2.py
59 lines (49 loc) · 1.35 KB
/
try2.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
import requests
import pandas as pd
from bs4 import BeautifulSoup
def getStars(n):
if (n<=1399):
return "1 star"
elif (n<=1599):
return "2 star"
elif (n<=1799):
return "3 star"
elif (n<=1999):
return "4 star"
elif (n<=2199):
return "5 star"
elif (n<=2499):
return "6 star"
else:
return "7 star"
url="https://www.codechef.com/users/chandravo"
r = requests.get(url)
htmlContent = r.content
soup = BeautifulSoup(htmlContent, 'html.parser')
# name = soup.find("h1", class_="h2-style").text
# print(name)
# global_rank = soup.find("a", href="/ratings/all").text
# print(global_rank)
# country_rank = soup.find("a", href=r"/ratings/all?filterBy=Country%3DIndia").text
# print(country_rank)
# rating_tmp = soup.find("div", class_="rating-number").text
# rating = ""
# for (i, char) in enumerate(rating_tmp):
# if char.isnumeric():
# rating += char
# else:
# continue
# print(rating)
# print(getStars(int(rating)))
# img=soup.find("img",class_="profileImage").attrs['src']
# print(img)
numq = soup.find("section", class_="rating-data-section problems-solved")
numq = numq.find("div",class_="content").find("h5").text
numq = numq[:-1]
for i in range(len(numq)-1, 0, -1):
if numq[i].isnumeric():
continue
else:
numq = numq[i+1:]
break
print(numq)