From 33dd9edcdc8987ee854c4ccd4b7048d06b60459a Mon Sep 17 00:00:00 2001 From: Thomas Wade Date: Wed, 19 Sep 2018 18:37:04 +0930 Subject: [PATCH] Actually use element provided by loop *facedesk* --- scrape.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scrape.py b/scrape.py index 350fe96..15e05ee 100755 --- a/scrape.py +++ b/scrape.py @@ -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