I am using the script below to get the Google News results for a brand. However, I would love to be able to export the results to a CSV or Excel file. Can someone help me out, please?
pip install pygooglenews --upgrade
from pygooglenews import GoogleNews
gn = GoogleNews(country = 'IE')
def get_titles(search):
stories = []
search = gn.search(search)
newsitem = search['entries']
for item in newsitem:
story = {
'title' : item.title,
'link' : item.link
}
stories.append(story)
return stories
print(get_titles('aldi'))
An easy (but heavy) way would be to use pandas, which easily converts a list of dictionaries into a data frame
The built-in way is answered here: How do I convert this list of dictionaries to a csv file?