From cdf78f02085e7a21c8bd20b4099098e7f57012ae Mon Sep 17 00:00:00 2001 From: Thomas Wade Date: Thu, 20 Sep 2018 00:59:13 +0930 Subject: [PATCH] Sprinkle a bit of NoneType safety into the mix --- scrape.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scrape.py b/scrape.py index 2194772..045aad6 100755 --- a/scrape.py +++ b/scrape.py @@ -145,7 +145,7 @@ def Get_Tracks_Info(url, limit = 100): track.artist = artist_elem.string.strip() # Check if we have already gotten this track before - if track.artist + track.title in tracks.keys(): + if str(track.artist) + str(track.title) in tracks.keys(): continue # Grab when it was uploaded @@ -169,10 +169,14 @@ def Get_Tracks_Info(url, limit = 100): track.comments = num # Grab the like count - track.likes = track_elem.find(class_='sc-button-like').string.strip() + like_elem = track_elem.find(class_='sc-button-like') + if like_elem: + track.likes = like_elem.string.strip() # Grab the repost count - track.reposts = track_elem.find(class_='sc-button-repost').string.strip() + repost_elem = track_elem.find(class_='sc-button-repost') + if repost_elem: + track.reposts = repost_elem.string.strip() # Finally add the track to the dictionary tracks[track.artist + track.title] = track