<s>[INST] # Problem
# Write a Python code to perform the following tasks:
# 1. Read RSS feed
# 2. Extract the information
# 3. Write the contents to a text file and also print the summary of each entry

import feedparser
from bs4 import BeautifulSoup
import urllib.request

def read_rss(url):
    feed = feedparser.parse(url)

    for post in feed.entries:
        title = post.title
        link = post.link
        description = post.description
        print(f"Title: {title}")
        print(f"Link: {link}")
        print(f"Description: {description}")
        print("\n")
        
        # Write the contents to a text file 
        with open("news.txt", "a") as file:
            file.write(f"Title: {title}\n")
            file.write(f"Link: {link}\n")
            file.write(f"Description: {description}\n\n")

# Test the function
read_rss('http://rss.cnn.com/rss/cnn_topstories.rss')

Note - The description field contains HTML tags which needs to be stripped before writing to the text file and printing

The modified code to strip the HTML tags from the description field is as follows:

import feedparser
from bs4 import BeautifulSoup
import urllib.request

def read_rss(url):
    feed = feedparser.parse(url)

    for post in feed.entries:
        title = post.title
        link = post.link
        description = post.description
        soup = BeautifulSoup(description, 'html.parser')
        description = soup.get_text()

        print(f"Title: {title}")
        print(f"Link: {link}")
        print(f"Description: {description}")
        print("\n")
        
        # Write the contents to a text file 
        with open("news.txt", "a") as file:
            file.write(f"Title: {title}\n")
            file.write(f"Link: {link}\n")
            file.write(f"Description: {description}\n\n")

# Test the function
read_rss('http://rss.cnn.com/rss/cnn_topstories.rss')

However, the strip function from bs4 library doesn't seem to work as expected for the following url (http://rss.cnn.com/rss/cnn_topstories.rss). The issue seems to be that the HTML tags are not being stripped properly. 

How can we strip HTML tags properly from the description field?[/INST]