python create RSS from html page
- User
python create RSS from html page
Assistant
Here is some Python code to create an RSS feed from an HTML page:
import feedparser from bs4 import BeautifulSoup html_page = """ <html> <head> <title>My Web Page</title> </head> <body> <h1>Latest News</h1> <h2>News Article 1</h2> <p>This is the text for news article 1</p> <h2>News Article 2</h2> <p>This is the text for news article 2</p> </body> </html> """ soup = BeautifulSoup(html_page, 'html.parser') items = [] for header in soup.find_all(['h1','h2']): item = {} item['title'] = header.text item['description'] = header.next_sibling.text items.append(item) rss = """<?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0"> <channel> <title>My Web Page</title> <link>http://www.example.com</link> <description>RSS feed for my web page</description> """ for item in items: rss += f""" <item> <title>{item['title']}</title> <description>{item['description']}</description> </item> """ rss += "</channel></rss>" print(rss)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.