Check for null results and flatten to string

This commit is contained in:
Thomas Wade 2018-09-27 16:46:03 +09:30
parent 86d7958489
commit 4e14ce2235

View File

@ -108,24 +108,27 @@ def Get_Basic_Info(user):
print(' Username: ' + user.username)
# Grab their track count
track_count = soup.find('a', href='/' + user.url_username + '/tracks', class_='infoStats__statLink').div.string
user.track_count = track_count
print(' Tracks: ' + user.track_count)
track_count_elem = soup.find('a', href='/' + user.url_username + '/tracks', class_='infoStats__statLink')
if track_count_elem:
user.track_count = str(track_count_elem.div.string)
print(' Tracks: ' + str(user.track_count))
# Grab their following count
following_count = soup.find('a', href='/' + user.url_username + '/following', class_='infoStats__statLink').div.string
user.following_count = following_count
following_count_elem = soup.find('a', href='/' + user.url_username + '/following', class_='infoStats__statLink')
if following_count_elem:
user.following_count = str(following_count_elem.div.string)
print(' Following: ' + str(user.following_count))
# Grab their follower count
follower_count = soup.find('a', href='/' + user.url_username + '/followers', class_='infoStats__statLink').div.string
user.follower_count = follower_count
follower_count_elem = soup.find('a', href='/' + user.url_username + '/followers', class_='infoStats__statLink')
if follower_count_elem:
user.follower_count = str(follower_count_elem.div.string)
print(' Followers: ' + str(user.follower_count))
# Grab their like count
like_count_elem = soup.find('a', href='/' + user.url_username + '/likes', class_='sidebarHeader__actualTitle')
if like_count_elem:
user.like_count = like_count_elem.string.split(' ')[0]
user.like_count = str(like_count_elem.string.split(' ')[0])
print(' Likes: ' + str(user.like_count))
# Gets a list of fully-populated Track objects