Actually use element provided by loop
*facedesk*
This commit is contained in:
parent
8c8631df7c
commit
33dd9edcdc
16
scrape.py
16
scrape.py
@ -120,18 +120,18 @@ def Get_Tracks_Info(user):
|
|||||||
|
|
||||||
tracks = {}
|
tracks = {}
|
||||||
|
|
||||||
track_elems = soup.find_all(class_='soundList__item')
|
track_elems = soup.find_all('li', class_='soundList__item')
|
||||||
for track_elem in track_elems:
|
for track_elem in track_elems:
|
||||||
# Initialise a track object to hold our data
|
# Initialise a track object to hold our data
|
||||||
track = Track()
|
track = Track()
|
||||||
|
|
||||||
# Grab the title
|
# Grab the title
|
||||||
title_elem = soup.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 = title_elem.span.string.strip()
|
||||||
|
|
||||||
# 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 = soup.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 = artist_elem.string.strip()
|
||||||
|
|
||||||
@ -140,17 +140,17 @@ def Get_Tracks_Info(user):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Grab when it was uploaded
|
# Grab when it was uploaded
|
||||||
date_elem = soup.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 = date_elem.time['datetime']
|
||||||
|
|
||||||
# Grab the first tag featured on the list item
|
# 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:
|
if tag_elem:
|
||||||
track.tag = tag_elem.string
|
track.tag = 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 = soup.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 = elem['title'].split(' ')
|
||||||
@ -160,10 +160,10 @@ def Get_Tracks_Info(user):
|
|||||||
track.comments = num
|
track.comments = num
|
||||||
|
|
||||||
# Grab the like count
|
# 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
|
# 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
|
# Finally add the track to the dictionary
|
||||||
tracks[track.artist + track.title] = track
|
tracks[track.artist + track.title] = track
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user