Flatten all track properties to strings
This commit is contained in:
parent
4e14ce2235
commit
f3d171a92b
14
scrape.py
14
scrape.py
@ -173,7 +173,7 @@ def Get_Tracks_Info(url, limit = 100):
|
|||||||
# Grab the title and url
|
# Grab the title and url
|
||||||
title_elem = track_elem.find(class_='soundTitle__title')
|
title_elem = track_elem.find(class_='soundTitle__title')
|
||||||
if title_elem:
|
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']
|
track.url = 'https://soundcloud.com' + title_elem['href']
|
||||||
|
|
||||||
# Check if we have already gotten this track before
|
# 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)
|
# Grab who uploaded it (usually the artist unless it's a label)
|
||||||
artist_elem = track_elem.find(class_='soundTitle__usernameText')
|
artist_elem = track_elem.find(class_='soundTitle__usernameText')
|
||||||
if artist_elem:
|
if artist_elem:
|
||||||
track.artist = artist_elem.string.strip()
|
track.artist = str(artist_elem.string.strip())
|
||||||
|
|
||||||
# Grab when it was uploaded
|
# Grab when it was uploaded
|
||||||
date_elem = track_elem.find(class_='soundTitle__uploadTime')
|
date_elem = track_elem.find(class_='soundTitle__uploadTime')
|
||||||
if date_elem:
|
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
|
# Grab the first tag featured on the list item
|
||||||
tag_elem = track_elem.find(class_='soundTitle__tagContent')
|
tag_elem = track_elem.find(class_='soundTitle__tagContent')
|
||||||
if tag_elem:
|
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)
|
# 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')
|
play_comment_elems = track_elem.find_all(class_='sc-ministats-item')
|
||||||
if play_comment_elems:
|
if play_comment_elems:
|
||||||
for elem in play_comment_elems:
|
for elem in play_comment_elems:
|
||||||
num, unit = elem['title'].split(' ')
|
num, unit = str(elem['title']).split(' ')
|
||||||
if unit == 'plays':
|
if unit == 'plays':
|
||||||
track.plays = num
|
track.plays = num
|
||||||
elif unit == 'comments':
|
elif unit == 'comments':
|
||||||
@ -208,12 +208,12 @@ def Get_Tracks_Info(url, limit = 100):
|
|||||||
# Grab the like count
|
# Grab the like count
|
||||||
like_elem = track_elem.find(class_='sc-button-like')
|
like_elem = track_elem.find(class_='sc-button-like')
|
||||||
if like_elem:
|
if like_elem:
|
||||||
track.likes = like_elem.string.strip()
|
track.likes = str(like_elem.string.strip())
|
||||||
|
|
||||||
# Grab the repost count
|
# Grab the repost count
|
||||||
repost_elem = track_elem.find(class_='sc-button-repost')
|
repost_elem = track_elem.find(class_='sc-button-repost')
|
||||||
if repost_elem:
|
if repost_elem:
|
||||||
track.reposts = repost_elem.string.strip()
|
track.reposts = str(repost_elem.string.strip())
|
||||||
|
|
||||||
# Finally add the track to the dictionary
|
# Finally add the track to the dictionary
|
||||||
tracks[track.url] = track
|
tracks[track.url] = track
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user