-
Notifications
You must be signed in to change notification settings - Fork 0
/
proms_scraper_year_piece_composer.py
169 lines (141 loc) · 5.38 KB
/
proms_scraper_year_piece_composer.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import csv
import requests
from bs4 import BeautifulSoup
# How do we find it:
# - Programme
# ul.ev-act-schedule__performances
# li.ev-act-schedule__performance-composer-segments
#### Composer name: a.ev-act-schedule__work-composer-name
#### Piece name: span.ev-act-schedule__performance-work-name
#### Duration: span.ev-act-schedule__performance-work-duration
#### Notes: span.ev-act-schedule__performance-work-note
###### Just get all text? All elements? List of text?
"""
Each day:
li.ev-event-calendar__single-date-events
- Each date:
h3.ev-event-calendar__date
Each concert:
li.ev-event-calendar__event-summary-container
- Each time:
div.ev-event-calendar__time
- Concert name:
div.ev-event-calendar__name > a.text
- Venue:
span.ev-event-calendar__event-location
Hidden details:
div.ev-event-calendar__description-and-schedule
Within that the details are:
li.ev-event-calendar__information
Container for each piece
li.ev-act-schedule__performance-composer-segments
- Composer:
a.ev-act-schedule__work-composer-name
- Piece name:
span.ev-act-schedule__performance-work-name
- Duration:
span.ev-act-schedule__performance-work-duration
- Notes:
span.ev-act-schedule__performance-work-note
"""
with open("proms_composer_data_all.csv", "w", encoding="utf-8", newline="") as f:
writer = csv.writer(f, delimiter="|")
for year in range(1895, 2022):
url = f"https://www.bbc.co.uk/proms/events/by/date/{year}"
html = requests.get(url).content
soup = BeautifulSoup(html, "lxml")
# Each day
day_query_tree = soup.find_all(
"li", class_="ev-event-calendar__single-date-events"
)
for date in day_query_tree:
# Date:
try:
date_query = date.find(
"h3", class_="ev-event-calendar__date"
).text.strip()
except:
date_query = "//"
# Each concert that day
concert_query_tree = date.find_all(
"div", class_="ev-event-calendar__information"
)
for concert in concert_query_tree:
# Time:
try:
time_query = concert.find(
"div", class_="ev-event-calendar__time"
).text.strip()
except:
time_query = "//"
# Concert Name:
try:
concert_name_query = concert.find(
"div", class_="ev-event-calendar__name"
).text.strip()
except:
concert_name_query = "//"
# Venue Name:
try:
venue_query = concert.find(
"span", class_="ev-event-calendar__event-location"
).text.strip()
except:
venue_query = "//"
# Piece query tree
try:
piece_query_tree = concert.find_all(
"li", class_="ev-act-schedule__performance-composer-segments"
)
except:
piece_query_tree = "//"
for piece in piece_query_tree:
# Check if Interval, if so continue
try:
if piece.find(
"span",
class_="ev-act-schedule__performance-segment-interval",
):
continue
except:
pass
# Composer:
try:
composer_query = piece.find(
"a", class_="ev-act-schedule__work-composer-name"
).text.strip()
except:
composer_query = "//"
# Piece name:
try:
piece_query = piece.find(
"span", class_="ev-act-schedule__performance-work-name"
).text.strip()
except:
piece_query = "//"
# Duration:
try:
duration_query = piece.find(
"span", class_="ev-act-schedule__performance-work-duration"
).text.strip()[1:-1]
except:
duration_query = "//"
# Notes:
try:
note_query = piece.find(
"span", class_="ev-act-schedule__performance-work-note"
).text.strip()
except:
note_query = "//"
writer.writerow(
[
date_query,
time_query,
concert_name_query,
venue_query,
composer_query,
piece_query,
duration_query,
note_query,
]
)