Если в общем виде, то примерно так:
from pprint import pprint
from urllib import request
from urllib.error import URLError
from bs4 import BeautifulSoup
def get_html_from_url(target_url):
try:
html = request.urlopen(target_url).read().decode('UTF-8')
return html
except URLError:
print('Не могу открыть url')
def parse_events(html_events):
events = list()
for item in html_events:
events.append({
'Событие': item.h3.a.string,
'Дата': item.p.time['datetime'],
'Место': item.find('span', {'class': 'event-location'}).string
})
return events
if __name__ == '__main__':
url = "https://www.python.org/events/python-events"
raw_html = get_html_from_url(url)
soup = BeautifulSoup(raw_html, 'html.parser')
item_list = soup.find('ul', attrs={'class': 'list-recent-events menu'})
python_events = parse_events(item_list.find_all('li'))
pprint(python_events)