Wednesday, September 11, 2024

parsefeed python library to compile blogposts into pdfs

extract rss feed to html with parsefeed python


import feedparser

# URL of the Atom feed
feed_url = "https://ecksesontress.blogspot.com/feeds/posts/default"

# Parse the feed
feed = feedparser.parse(feed_url)

# Open file for writing (creates the file if it doesn't exist)
with open('blogposts.html', 'w') as file:
    # Write the beginning of the HTML document
    file.write("\n\nBlog Posts\n\n\n")
    
    # Iterate over the entries (posts) and extract titles and summaries
    for entry in feed.entries[:10]:  # Limit to the first 10 entries
        title = entry.title
        summary = entry.summary  # This is typically the body content
        
        # Write the title as an  and the summary (body) below it
        file.write(f"{title}\n")
        file.write(f"{summary}\n")
        file.write("\n")  # Separator for readability

    # Write the end of the HTML document
    file.write("\n\n")

No comments:

Post a Comment