Skip to content

Commit 02674f4

Browse files
authored
fix: fix codechef contest script (#1386)
* fixed bug and made the neessary changes * made small changes
1 parent 8df07a7 commit 02674f4

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

Python/Codechef_Contests/codechef_contests.py

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,20 @@
22
from bs4 import BeautifulSoup
33
from prettytable import PrettyTable
44

5-
t = PrettyTable(["Code", "Name", "Start"]) # to create table
5+
t = PrettyTable(["Name", "Start","Link"]) # to create table
66

7-
# print (t)
7+
url = "https://www.codechef.com/"
88

9-
url = "https://www.codechef.com/contests"
9+
page = requests.get(url).text # send request to cc srver and returns the page
1010

11-
page = requests.get(url) # send request to cc srver and returns the page
11+
soup = BeautifulSoup(page, "lxml") # store html content in soup
1212

13-
soup = BeautifulSoup(page.content, "html.parser") # store html content in soup
13+
table = soup.findAll('div',class_='l-card-3 m-other-event-card')
1414

15-
# print (soup.prettify()) #prettify() to print the html code in well intended form
16-
17-
# return the tables with class=dataTable
18-
table = soup.findAll("table", class_="dataTable")
19-
20-
# print (len(table))
21-
22-
req_table = table[1]
23-
24-
tr = req_table.tbody.findAll("tr") # tr from all tbody tag
25-
26-
# print (len(tr))
27-
28-
# td = tr[0].findAll('td') #find all td from tr[0]
29-
30-
# print (len(td))
31-
# print (td[0].text)
32-
33-
for i in range(len(tr)):
34-
td = tr[i].findAll("td")
35-
# add_row takes a 'list' of data
36-
t.add_row([td[0].text, td[1].text, td[2].text])
15+
for i in table:
16+
nm = i.h3.text
17+
dt = i.find('p',class_= 'm-card-3__day').text + i.find('p',class_= 'm-card-3__month').text + i.find('span',class_='m-card-3__time-clock').text
18+
lnk =i.find('a',class_='m-card-3__dtl-btn')['href']
19+
t.add_row([nm,dt,lnk])
3720

3821
print(t)

0 commit comments

Comments
 (0)