简体   繁体   中英

Retrieving JSON Title, URL from Pygooglenews feedParser

I'm trying to retrieve values from pyGoogleNews ( https://github.com/kotartemiy/pygooglenews ) that is using feedParser to output the values.

库信息

Code Snippet as follows:

from pygooglenews import GoogleNews

gn = GoogleNews(lang = 'en', country = 'SG')
cars = gn.topic_headlines('CAAqJAgKIh5DQkFTRUFvSEwyMHZNR3MwYWhJRlpXNHRSMElvQUFQAQ')
print(cars)

which returns the following: (does not seem like a valid JSON file)

在此处输入图像描述

What I'm trying to achieve is to loop the "entries" list, to get the relevant title and link.

How do I go about doing this?

The solution as follows:

for item in cars['entries']:
    print(item['title'])
    print(item['link'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM