If you are developing a social networking website with news and stories, you may be interested to present the news from various world news agencies, such as BBC and Reuters. Let us try to read news from BBC via a Python script.
This recipe relies on Python's third-party feedparser
library. You can install this by running the following command:
$ pip install feedparser
Or
$ easy_install feedparser
First, we collect the BBC's news feed URL from the BBC website. This URL can be used as a template to search news on various types, such as world, UK, health, business, and technology. So, we can take the type of news to display as user input. Then, we depend on the read_news()
function, which will fetch the news from the BBC.
Listing 6.6 explains how to read news feed from the BBC, as shown in the following code:
#!/usr/bin/env python # Python Network Programming Cookbook -- Chapter - 6 # This program is optimized for Python 2.7. # It may run...