Skip to content

Instantly share code, notes, and snippets.

@eyeseast
Created February 21, 2011 03:23
Show Gist options
  • Select an option

  • Save eyeseast/836621 to your computer and use it in GitHub Desktop.

Select an option

Save eyeseast/836621 to your computer and use it in GitHub Desktop.
from lxml.html import parse
def get_feed(url):
"""
Find the first link to an XML feed (rss or atom) and return the URL
"""
page = parse(url).getroot()
page.make_links_absolute()
for link in page.head.findall('links'):
if link.get('type', '').lower() in ('application/rss+xml', 'application/atom+xml'):
return link.get('href')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment