Improve broken XML support

TPB feed is a good example <http://rss.thepiratebay.sx/blog>. Now supports ampersand in feed, using the "recover" mode in etree.parse. Broken utf-8 strings in feed are now also supported.
master
pictuga 2013-09-08 15:48:34 +02:00
parent 5ebd84ee55
commit 1b7fdad6a8
1 changed files with 4 additions and 1 deletions

View File

@ -42,7 +42,10 @@ class FeedException(Exception):
pass
def parse(data):
doc = etree.fromstring(data)
data = data.decode('utf-8', 'replace').encode('utf-8')
parser = etree.XMLParser(recover=True)
doc = etree.fromstring(data, parser)
match = doc.xpath("//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF", namespaces=NSMAP)
if len(match):
mtable = { 'rdf:rdf': FeedParserRSS, 'channel': FeedParserRSS,