32 lines
931 B
Python
32 lines
931 B
Python
import feedparser
|
|
import os
|
|
import requests
|
|
|
|
def download_attachment(url, filename):
|
|
response = requests.get(url)
|
|
if response.status_code == 200:
|
|
try:
|
|
with open(filename, 'wb') as f:
|
|
f.write(response.content)
|
|
print(f"Downloaded {filename}")
|
|
except:
|
|
print("Download Failure")
|
|
print(url)
|
|
print(filename)
|
|
else:
|
|
print(f"Failed to download {url}")
|
|
|
|
def main():
|
|
feed_url = input("Enter the RSS feed URL: ")
|
|
num_entries = int(input("Enter the number of entries to process: "))
|
|
feed = feedparser.parse(feed_url)
|
|
for i, entry in enumerate(feed.entries[:num_entries]):
|
|
if hasattr(entry, 'links'):
|
|
for link in entry.links:
|
|
url = link.href
|
|
name = str(link.href.split("/")[-1])
|
|
download_attachment(url, name)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|