From f3d171a92be48e65f345e31dda25bcd3127b19e9 Mon Sep 17 00:00:00 2001 From: Thomas Wade Date: Thu, 27 Sep 2018 16:54:40 +0930 Subject: [PATCH] Flatten all track properties to strings --- scrape.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scrape.py b/scrape.py index f2853b8..5403d96 100755 --- a/scrape.py +++ b/scrape.py @@ -173,7 +173,7 @@ def Get_Tracks_Info(url, limit = 100): # Grab the title and url title_elem = track_elem.find(class_='soundTitle__title') if title_elem: - track.title = title_elem.span.string.strip() + track.title = str(title_elem.span.string.strip()) track.url = 'https://soundcloud.com' + title_elem['href'] # Check if we have already gotten this track before @@ -183,23 +183,23 @@ def Get_Tracks_Info(url, limit = 100): # Grab who uploaded it (usually the artist unless it's a label) artist_elem = track_elem.find(class_='soundTitle__usernameText') if artist_elem: - track.artist = artist_elem.string.strip() + track.artist = str(artist_elem.string.strip()) # Grab when it was uploaded date_elem = track_elem.find(class_='soundTitle__uploadTime') if date_elem: - track.date = date_elem.time['datetime'] + track.date = str(date_elem.time['datetime']) # Grab the first tag featured on the list item tag_elem = track_elem.find(class_='soundTitle__tagContent') if tag_elem: - track.tag = tag_elem.string + track.tag = str(tag_elem.string) # Grab the play and comment counts (either of these may or may not be present) 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(' ') + num, unit = str(elem['title']).split(' ') if unit == 'plays': track.plays = num elif unit == 'comments': @@ -208,12 +208,12 @@ def Get_Tracks_Info(url, limit = 100): # Grab the like count like_elem = track_elem.find(class_='sc-button-like') if like_elem: - track.likes = like_elem.string.strip() + track.likes = str(like_elem.string.strip()) # Grab the repost count repost_elem = track_elem.find(class_='sc-button-repost') if repost_elem: - track.reposts = repost_elem.string.strip() + track.reposts = str(repost_elem.string.strip()) # Finally add the track to the dictionary tracks[track.url] = track