-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupcoming_hackathons.py
24 lines (15 loc) · 1.18 KB
/
upcoming_hackathons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests #imports request
from bs4 import BeautifulSoup #imports BeautifulSoup
req = requests.get('https://hackevents.co/hackathons') #fetch request from url
soup = BeautifulSoup(req.text, 'lxml')
hack = soup.find_all('div', {'class': 'hackathon'}) #finds all element with div class equal hackathon
print("{:<5} {:<15}: {:<90} : {}, {}\n".format('Sr.No.', 'Date', 'Name of Hackathon', 'City', 'Country'))
for i, f in enumerate(hack, 1):
month = f.find('div', {'class': 'date'}).find('div', {'class': 'date-month'}).text.strip()
day_num = f.find('div', {'class': 'date'}).find('div', {'class': 'date-day-number'}).text.strip()
week_day = f.find('div', {'class': 'date'}).find('div', {'class': 'date-week-days'}).text.strip()
display = "{} {} {} ".format(day_num, week_day, month)
name = f.find('div', {'class': 'info'}).find('h2').text.strip()
city = f.find('div', {'class': 'info'}).find('p').find('span', {'class': 'city'}).text.strip()
country = f.find('div', {'class': 'info'}).find('p').find('span', {'class': 'country'}).text.strip()
print("{:<5} {:<15} : {:<90} : {}, {}\n".format(str(i)+')', display, name.title(), city, country)) #print it out