I am trying to make another set of key-value pairs for each set of a show (set1, set2, encore) scraped from setlist.fm instead of just the list of songs without separation. What I cannot figure out is how to access the elements that state the set of the show and then append the list of songs after it until it hits the next set. Here is the html I am accessing: html code from setlist fm
Currently, my JSON file looks like this:
'''`{
"artist": "Sample Artist",
"day": 20,
"month": 1,
"songs": ["Song A","Song B","Song C"
],
"tour": "2000 U.S. Tour",
"venue": "Sample Venue, Atlanta, GA, USA",
"year": 2000
},`
whereas I want it to look like this:
"artist": "Sample Artist",
"day": 20,
"month": 1,
"songs": ["Song A","Song B","Song C"
],
"set1": ["Song A"],
"set2": ["Song B"],
"encore":["Song C"],
"tour": "2000 U.S. Tour",
"venue": "Sample Venue, Atlanta, GA, USA",
"year": 2000
},`
Here is the code I am using to generate the song list of the JSON but am not sure how to get the sets individually:
def getConcertData(i, url, concerts):
try:
soup = getSoup(url)
dateBlock = soup.find_all("div", {"class": "dateBlock"})[0]
infoContainer = soup.find_all("div", {"class": "infoContainer"})[0]
headLineDiv = infoContainer.find_all("div", {"class": "setlistHeadline"})[0]
setlistDiv = soup.find_all("div", {"class": "setlistList"})[0]
#removed unrelated code for question
songs = []
for a in setlistDiv.find_all("a", {"class": "songLabel"}):
songs.append(a.getText().strip())
print(str(year)+"."+str(month).zfill(2)+"."+str(day).zfill(2)+": "+venue)
data = dict()
data["artist"] = artist
data["year"] = year
data["month"] = month
data["day"] = day
data["venue"] = venue
data["tour"] = tour
data["songs"] = songs
# data["set1"] = 0
# data["set2"] = 0
# data["encore"] = 0
concerts[i] = data