Created
February 26, 2023 16:41
-
-
Save patrickelectric/dfa146cd680e3279dd128763eb1b9b53 to your computer and use it in GitHub Desktop.
Scrap event from ney matogrosso website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
from bs4 import BeautifulSoup | |
url = 'https://neymatogrosso.com.br/agenda/' | |
headers = { | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" | |
} | |
response = requests.get(url, headers=headers) | |
soup = BeautifulSoup(response.text, 'html.parser') | |
events = [] | |
# Find the div with id "agenda" | |
agenda_div = soup.find('div', id='agenda') | |
# Find all items with the class "item" | |
for item in agenda_div.find_all('div', class_='item'): | |
# Extract the event data from the content div | |
content_div = item.find('div', class_='content') | |
date = content_div.find('p', class_='data').text.strip() | |
city = content_div.find('h3').text.strip() | |
venue = content_div.find('h6').text.strip() | |
# Check if there's a link to the tickets | |
link = content_div.find('a', class_='botao') | |
if link is not None: | |
tickets_url = link['href'] | |
else: | |
tickets_url = None | |
# Create a dictionary to represent the event | |
event = { | |
'date': date, | |
'city': city, | |
'venue': venue, | |
'tickets_url': tickets_url | |
} | |
# Add the event to the list | |
events.append(event) | |
for event in events: | |
print("---") | |
for key, value in event.items(): | |
print(f'{key}: {value}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment