所以我有这个使用 Google API 和报纸的脚本(运行 Python 3.5)。它在谷歌搜索与睡眠有关的文章。然后使用报纸,我遍历这些 URL。我要求 Newspaper 做的只是返回该文章的关键字列表,我将其称为 write article.keywords
。
for url in google.search('sleep', num=2, stop=1):
article = Article(url)
article.download()
article.parse()
article.nlp()
print(article.keywords)
返回的关键字(对于给定的文章)如下所示:
['education', 'nights', 'start', 'pill', 'supplement', 'research', 'national', 'sleep', 'sleeping', 'trouble', 'using', 'taking']
但是我想为所有结果创建一个包含所有关键字的字典:也就是说,每个被迭代的文章的关键字。我该怎么做?