extract links from craigslist rdf feeds with python

note the use of urlfetch — i’m using this in an app engine application.

from BeautifulSoup import BeautifulSoup

class RDF(dict):
  def __init__(self, url):
    try:
      self['contents'] = BeautifulSoup(urlfetch.fetch(url).contents)
    except:
      self['contents'] = ''
  def links(self):
    [ item['rdf:about'] for item in self['contents'].findAll('item') ] 

if __name__ == '__main__'
  from __main__ import RDF
  url = 'http://sfbay.craigslist.org/search/apa/sfc?format=rss&bedrooms=2&s=0&maxAsk=3000'
  print RDF(url).links

About this entry