我一直在编写一个 python 脚本来抓取 Billboard.com 并创建一个包含曲目标题和艺术家姓名的数据框。下面是相关的代码片段:
#compiles top 100 artist names/tracks
song_list = pd.DataFrame(
{
'tracks': tracks,
'artists': artists,
})
#search for each song and add as track id
track =
artist =
track_id = sp.search(q='artist:' + artist + ' track:' + track, type='track')
#create the playlist with the set variables/add tracks
if token:
sp = spotipy.Spotify(auth=token)
sp.trace = False
playlists = sp.user_playlist_create(username, playlist_name,
description=playlist_description)
results = sp.user_playlist_add_tracks(username, playlist_id, track_ids)
print(results)
pprint.pprint(playlists)
else:
print("Can't get token for", username)
我试图从数据框中搜索每个艺术家姓名+曲目标题并将其添加到新创建的播放列表中。我知道我必须使用 for 循环,但我不确定如何将它与 spotipys 搜索功能结合使用。谢谢。