Skip to content

Commit

Permalink
Reto mouredev#18 - Python
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscocontreras93 committed May 2, 2023
1 parent 88f038a commit 3573a96
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import requests
from bs4 import BeautifulSoup as bs

url = 'https://holamundo.day/'
site = requests.get(url)
soup = bs(site.content,"html.parser")

class RetoWebScrapping():
def __init__(self,url:str) -> None:
"""
Args:
url (str): url to the website to scrap
"""
self.site = requests.get(url)
self.soup = bs(site.content,"html.parser")
self.agenda = {}

def find(self,day:int):
"""Function to search for events on a given day
Args:
day (int):
"""
for e in self.soup.find_all('h1'):
title = e
n = title.find_next_sibling('blockquote')
evento = title.text
if evento.find(str(day)) != -1:
print(evento)
while n != None:
evento = n.text
evento = evento.split(' | ',1)
self.agenda[evento[0]] = evento[1]

n = n.find_next_sibling('blockquote')
self.printAgenda(self.agenda)



def printAgenda(self,agenda):
for h, v in agenda.items():
print('Hora: {} --- {}'.format(h,v))

pass


reto = RetoWebScrapping(url)
reto.find(8)

0 comments on commit 3573a96

Please sign in to comment.