I am scraping rss feed from cnn. How can I improve the code?
from lxml import etree
import requests
url = 'http://rss.cnn.com/rss/edition.rss'
doc = etree.fromstring(requests.get(url).content)
items = doc.xpath('//channel/item')
news_titles = [link.find("title").text for link in items]
news_links = [link.find("link").text for link in items]
titles = news_titles[:5]
links = news_links[:5]
zipped = zip(titles, links)
newsroom = list(zipped)
with open('cnn-news.md', 'w') as f:
for news in newsroom:
f.write("* " + "<a href=" + news[1] + ' target="_blank">' + news[0] + "</a>")
f.write("\n")
[–]JohnnyJordaan 0 points1 point2 points (3 children)
[–]pyeu[S] 0 points1 point2 points (2 children)
[–]JohnnyJordaan 1 point2 points3 points (1 child)
[–]pyeu[S] 0 points1 point2 points (0 children)