所以我使用这个python包lyricsgenius
从网站 genius.com 使用网站的API抓取歌词。在这个脚本中,我希望它刮掉德雷克的 300 首歌曲:
import lyricsgenius
genius = lyricsgenius.Genius(API_KEY)
artist = genius.search_artist("Drake", max_songs=300, sort="title")
但是,它停在歌曲 106 处并显示错误消息:
Song 106: "Draft Day"
"Drake & DJ Semtex Interview" is not valid. Skipping.
Timeout raised and caught:
HTTPSConnectionPool(host='api.genius.com', port=443): Read timed out. (read timeout=5)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-575a1d98f954> in <module>
1 genius = lyricsgenius.Genius(API_KEY)
----> 2 artist = genius.search_artist("Drake", max_songs=300, sort="title")
~/anaconda3/lib/python3.7/site-packages/lyricsgenius/api.py in search_artist(self, artist_name, max_songs, sort, per_page, get_full_info, allow_name_change, artist_id)
329 else:
330 info = {'song': song_info}
--> 331 song = Song(info, lyrics)
332
333 # Attempt to add the Song to the Artist
~/anaconda3/lib/python3.7/site-packages/lyricsgenius/song.py in __init__(self, json_dict, lyrics)
24 save_lyrics: Save the song lyrics to a JSON or TXT file.
25 """
---> 26 self._body = json_dict['song'] if 'song' in json_dict else json_dict
27 self._body['lyrics'] = lyrics
28 self._url = self._body['url']
TypeError: argument of type 'NoneType' is not iterable
如何设置,使其在达到 300 首歌曲时停止抓取?
-
意识到这是正在使用的
lyricsgenius
包中的一个问题(即使存在内部故障,它也应该正确报告)。 -
检查它是否适用于最新版本的软件包。你的
lyricsgenius.__version__
是什么?最新的似乎是 1.6.0,它仅在 3 天前创建。尝试手动安装它(pip install lyricsgenius
)。 -
如果问题仍然存在,请查找官方存储库以获取联系方式。Python 包索引将您发送到 https://github.com/johnwmillr/LyricsGenius/issues。该项目的自述文件说"只是打开一个问题"。