-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrapingMadrid.py
42 lines (33 loc) · 1.51 KB
/
scrapingMadrid.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
39
40
41
import sys
from bs4 import BeautifulSoup
def scrape_club_info(file_path, club_name):
# Read the HTML content
with open(file_path, 'r', encoding='utf-8') as file:
html_content = file.read()
# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(html_content, 'html.parser')
# Scraping the relevant information
club_info = {
'Name': club_name,
'Address': soup.find(text='Address').find_next().get_text(strip=True) if soup.find(text='Address') else 'Not Found',
'Contact info': soup.find(text='Telephone').find_next().get_text(strip=True) if soup.find(text='Telephone') else 'Not Found',
'Type': soup.find(text='Type').find_next().get_text(strip=True) if soup.find(text='Type') else 'Not Found',
'times': soup.find(text='Times').find_next().get_text(strip=True) if soup.find(text='Times') else 'Not Found',
}
return club_info
# Scraping Done for the chosen specific clubs in Madrid.
# Paths to HTML files
file_paths = [
('Clubs_Scraping/goya.html', 'Goya Social Club'),
('Clubs_Scraping/panda.html', 'Panda Club'),
('Clubs_Scraping/ICON.html', 'Icon Club'),
('Clubs_Scraping/Lab.html', 'Lab Club'),
('Clubs_Scraping/panda.html', 'Panda'),
('Clubs_Scraping/commo.html', 'Commo'),
('Clubs_Scraping/sala.html', 'Sala'),
]
# Scraping information for each club
clubs_data = [scrape_club_info(path, name) for path, name in file_paths]
# Printing the scraped information
for club in clubs_data:
print(club)