Actually use element provided by loop

*facedesk*
This commit is contained in:
Thomas Wade 2018-09-19 18:37:04 +09:30
parent 8c8631df7c
commit 33dd9edcdc

View File

@ -120,18 +120,18 @@ def Get_Tracks_Info(user):
tracks = {}
track_elems = soup.find_all(class_='soundList__item')
track_elems = soup.find_all('li', class_='soundList__item')
for track_elem in track_elems:
# Initialise a track object to hold our data
track = Track()
# Grab the title
title_elem = soup.find(class_='soundTitle__title')
title_elem = track_elem.find(class_='soundTitle__title')
if title_elem:
track.title = title_elem.span.string.strip()
# Grab who uploaded it (usually the artist unless it's a label)
artist_elem = soup.find(class_='soundTitle__usernameText')
artist_elem = track_elem.find(class_='soundTitle__usernameText')
if artist_elem:
track.artist = artist_elem.string.strip()
@ -140,17 +140,17 @@ def Get_Tracks_Info(user):
continue
# Grab when it was uploaded
date_elem = soup.find(class_='soundTitle__uploadTime')
date_elem = track_elem.find(class_='soundTitle__uploadTime')
if date_elem:
track.date = date_elem.time['datetime']
# Grab the first tag featured on the list item
tag_elem = soup.find(class_='soundTitle__tagContent')
tag_elem = track_elem.find(class_='soundTitle__tagContent')
if tag_elem:
track.tag = tag_elem.string
# Grab the play and comment counts (either of these may or may not be present)
play_comment_elems = soup.find_all(class_='sc-ministats-item')
play_comment_elems = track_elem.find_all(class_='sc-ministats-item')
if play_comment_elems:
for elem in play_comment_elems:
num, unit = elem['title'].split(' ')
@ -160,10 +160,10 @@ def Get_Tracks_Info(user):
track.comments = num
# Grab the like count
track.likes = soup.find(class_='sc-button-like').string.strip()
track.likes = track_elem.find(class_='sc-button-like').string.strip()
# Grab the repost count
track.reposts = soup.find(class_='sc-button-repost').string.strip()
track.reposts = track_elem.find(class_='sc-button-repost').string.strip()
# Finally add the track to the dictionary
tracks[track.artist + track.title] = track