import requests import xml.etree.ElementTree as ET URL = "https://feeds.feedburner.com/TheHackersNews?format=xml" FEED_FILE = "feed.xml" def downloadRSS(): response = requests.get(URL) with open(FEED_FILE, 'wb') as file: file.write(response.content) def parseXML(xmlfile): # create element tree object tree = ET.parse(xmlfile) # get root element root = tree.getroot() # create empty list for news items newsitems = [] # iterate news items for item in root.findall('./channel/item'): # empty news dictionary news = {} # iterate child elements of item for child in item: # # special checking for namespace object content:media if child.tag == '{http://search.yahoo.com/mrss/}content': news['media'] = child.attrib['url'] else: if child.text is not None: news[child.tag] = child.text.encode('utf8') # append news dictionary to news items list newsitems.append(news) # return news items list return newsitems def saveToHTML(articles): # create news article list with open("news_scroll.html", "w") as news: news.write('\ \n\ \n\
\n\ \n\{content}...
\n\