python create RSS from html page
- User
python create RSS from html page
Assistant
import feedparser import requests from bs4 import BeautifulSoup def create_rss_from_html(url, title, description): """Creates an RSS feed from an HTML page. Args: url: The URL of the HTML page. title: The title of the RSS feed. description: The description of the RSS feed. Returns: An RSS feed as a string. """ # Get the HTML content of the page. response = requests.get(url) html = response.text # Parse the HTML content. soup = BeautifulSoup(html, 'html.parser') # Get the title and description of the page. title = soup.title.string description = soup.find('meta', attrs={'name': 'description'})['content'] # Get the items from the page. items = [] for item in soup.find_all('item'): title = item.find('title').string description = item.find('description').string link = item.find('link').string pubDate = item.find('pubDate').string items.append({ 'title': title, 'description': description, 'link': link, 'pubDate': pubDate }) # Create the RSS feed. rss = feedparser.FeedParserDict() rss['version'] = '2.0' rss['title'] = title rss['description'] = description rss['link'] = url rss['entries'] = items # Return the RSS feed as a string. return rss.writeString('utf-8') # Example usage. url = 'https://www.example.com/news.html' title = 'Example News' description = 'The latest news from Example.com.' rss = create_rss_from_html(url, title, description) 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.