Check if the user exists through their username element
This commit is contained in:
parent
61df852e63
commit
ba9be2ee3f
19
scrape.py
19
scrape.py
@ -138,9 +138,14 @@ def Get_Basic_Info(user):
|
|||||||
|
|
||||||
# Grab their username
|
# Grab their username
|
||||||
# Use stripped_strings generator as workaround for users with premium badge
|
# Use stripped_strings generator as workaround for users with premium badge
|
||||||
username = next(soup.find(class_='profileHeaderInfo__userName').stripped_strings)
|
username_elem = soup.find(class_='profileHeaderInfo__userName')
|
||||||
user.username = username
|
if username_elem:
|
||||||
print(' Username: ' + user.username)
|
username = next(username_elem.stripped_strings)
|
||||||
|
user.username = username
|
||||||
|
print(' Username: ' + user.username)
|
||||||
|
else:
|
||||||
|
print(' No username, cannot be a valid user')
|
||||||
|
return False
|
||||||
|
|
||||||
# Grab their track count
|
# Grab their track count
|
||||||
track_count_elem = soup.find('a', href='/' + user.url_username + '/tracks', class_='infoStats__statLink')
|
track_count_elem = soup.find('a', href='/' + user.url_username + '/tracks', class_='infoStats__statLink')
|
||||||
@ -166,6 +171,8 @@ def Get_Basic_Info(user):
|
|||||||
user.like_count = Human_Str_To_Int(str(like_count_elem.string.split(' ')[0]))
|
user.like_count = Human_Str_To_Int(str(like_count_elem.string.split(' ')[0]))
|
||||||
print(' Likes: ' + str(user.like_count))
|
print(' Likes: ' + str(user.like_count))
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
# Gets a list of fully-populated Track objects
|
# Gets a list of fully-populated Track objects
|
||||||
def Get_Tracks_Info(url, limit = 100):
|
def Get_Tracks_Info(url, limit = 100):
|
||||||
# Get the page and soup it
|
# Get the page and soup it
|
||||||
@ -384,8 +391,10 @@ if not args.dump:
|
|||||||
user.url_username = user_str
|
user.url_username = user_str
|
||||||
print(' URL Username: ' + user.url_username)
|
print(' URL Username: ' + user.url_username)
|
||||||
|
|
||||||
# Get their basic info
|
# Get their basic info and check if it was successful
|
||||||
Get_Basic_Info(user)
|
if not Get_Basic_Info(user):
|
||||||
|
print(' Failed to get basic info, skipping')
|
||||||
|
continue
|
||||||
|
|
||||||
# Get their tracks
|
# Get their tracks
|
||||||
for track in Get_Tracks_Info('https://soundcloud.com/' + user.url_username + '/tracks', USER_MAX_TRACKS):
|
for track in Get_Tracks_Info('https://soundcloud.com/' + user.url_username + '/tracks', USER_MAX_TRACKS):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user