Check if element exists before parsing

This commit is contained in:
Thomas Wade 2018-09-18 17:45:54 +09:30
parent b8a6a431bf
commit 9b9345887b

View File

@ -73,9 +73,9 @@ for user_str in users_to_process:
user.track_count = track_count user.track_count = track_count
# Grab their like count # Grab their like count
like_count = soup.find('a', href='/' + user.url_username + '/likes').find(class_='sidebarHeader__actualTitle').string.split(' ')[0] like_count_elem = soup.find('a', href='/' + user.url_username + '/likes').find(class_='sidebarHeader__actualTitle')
user.like_count = like_count if like_count_elem:
user.like_count = like_count_elem.string.split(' ')[0]
# Finally add the user to the dictionary # Finally add the user to the dictionary
user_dict[user.url_username] = user user_dict[user.url_username] = user