【发布时间】:2022-01-21 06:05:31
【问题描述】:
我是 Python 新手,我正在尝试使用 PyGoogleNews 库从 Google News Feed 中提取标题。我正在使用谷歌 Colab。 PyGoogleNews 代码对我来说运行得很好,我对此很满意。代码正在创建 csv,但我无法使用抓取的标题结果填充 csv。我想将抓取的标题输出导出到 csv 文件中,因为我将执行情绪分析并下载/提取它以对其进行进一步分析。我会非常感谢任何帮助,因为这已经困扰了我好几天了,我相信这是非常明显的事情!提前谢谢你。
!pip install pygooglenews --upgrade
import pandas as pd
import csv
from pygooglenews import GoogleNews
gn = GoogleNews (lang = 'en', country = 'UK')
Xmassearch = gn.search('intitle:Christmas', helper = True, from_ = '2019-12-01', to_= '2019-12-31')
print(Xmassearch['feed'].title)
for item in Xmassearch ['entries']:
print(item['title'])
file = open("Christmassearch.csv", "w")
writer = csv.writer(file)
writer.writerow(["Xmassearch"])
file.close()
【问题讨论】:
标签: python csv export pygooglenews