4
votes

I'm trying to download a corpus of news (to try to do some natural language processing) from Google News using the universal feedparser with python. I really know nothing of XML, I'm just using an example of how to use the feedparser. The problem is that I can't find in the dict I get from the RSS feed the content of the news just the title.

The code I'm currently trying to use is this:

import feedparser
url = 'http://news.google.com.br/news?pz=1&cf=all&ned=us&hl=en&output=rss' 
# just some GNews feed - I'll use a specific search later

feed = feedparser.parse(url)
for post in feed.entries:
   print post.title
   print post.keys()

The keys I get in this post are just the title, summary, date, etc... there's no content.

Is this some issue with Google News or am I doing anything wrong? Is there a way to do it?

2
Google news doesn't store the actual content a far as I know, just a summary to the content. You will need to scrape the site it links to for the content.Bartek
:( I just realized that this is true of almost every relevant news source worldwide. The RSS feed never contain the full text of the news, just the summary. I think I'll have to learn how to use BeautifulSoup.Rafael S. Calsaverini
I just realized how to parse some pages with BeautifulSoup. Thanks for your answers.Rafael S. Calsaverini

2 Answers

8
votes

Have you examined the feed from Google News?

There is a root element in each feed which contains a bunch of information and the actual entries dict. Here's a dirty way to see what's available:

import feedparser
d = feedparser.parse('http://news.google.com/news?pz=1&cf=all&ned=ca&hl=en&topic=w&output=rss')

print [field for field in d]

From what we can see we have an entries field which most likely contains .. news entries! If you:

import pprint
pprint.pprint(entry for entry in d['entries'])

We get some more information :) That will show you all the fields related to each entry in a pretty printed manner (that's what pprint is for)

So, to fetch all the titles of our news entries from this feed:

titles = [entry.title for entry in d['entries']

so, play around with that. Hopefully that's a helpful start

1
votes

First you need to check out RSS Specification. And here is a feed parser. That should get you started.