forked from HarshCasper/Rotten-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codechef_contests.py
38 lines (23 loc) · 898 Bytes
/
codechef_contests.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
import requests
from bs4 import BeautifulSoup
from prettytable import PrettyTable
t = PrettyTable(['Code', 'Name', 'Start']) # to create table
#print (t)
url = 'https://www.codechef.com/contests'
page = requests.get(url) # send request to cc srver and returns the page
soup = BeautifulSoup(page.content, 'html.parser') # store html content in soup
# print (soup.prettify()) #prettify() to print the html code in well intended form
# return the tables with class=dataTable
table = soup.findAll('table', class_="dataTable")
#print (len(table))
req_table = table[1]
tr = req_table.tbody.findAll('tr') # tr from all tbody tag
#print (len(tr))
# td = tr[0].findAll('td') #find all td from tr[0]
#print (len(td))
#print (td[0].text)
for i in range(len(tr)):
td = tr[i].findAll('td')
# add_row takes a 'list' of data
t.add_row([td[0].text, td[1].text, td[2].text])
print(t)