Created
January 19, 2016 07:42
-
-
Save pmolchanov/6f1289a3ca6821b5c967 to your computer and use it in GitHub Desktop.
Parse Craigslist RSS Feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from lxml import etree | |
def parseCraigslistRssFeed(url): | |
listings = [] | |
xml = etree.parse(url) | |
channel = xml.getroot().find('{*}channel') | |
items = xml.getroot().findall('{*}item') | |
for item in items: | |
title = item.find('{*}title').text | |
desc = item.find('{*}description').text | |
date = item.find('{*}date').text | |
link = item.find('{*}link').text | |
enclosure = item.find('{*}enclosure') | |
imgsrc = None | |
if enclosure is not None: | |
imgsrc = item.find('{*}enclosure').attrib.get('resource') | |
listings.append({ | |
'title': title, | |
'desc': desc, | |
'date': date, | |
'link': link, | |
'imgsrc': imgsrc | |
}) | |
return listings | |
print(parseCraigslistRssFeed('''http://miami.craigslist.org/search/sga?format=rss&is_paid=all&query=surfboard&search_distance_type=mi''')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment