Using Python 3
Error we get:
File "C:/scratch.py", line 27, in run
tree = ET.fromstring(responses[0].decode(), ET.XMLParser(encoding='utf-8'))
File "C:\Programs\Python\Python36-32\lib\xml\etree\ElementTree.py", line 1314, in XML
parser.feed(text)
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 163, column 1106
Our code:
tree = ET.fromstring(responses[0].decode(), ET.XMLParser(encoding='utf-8'))
for i in tree.iter('item'):
try:
title = i.find('title').text
except Exception:
pass
The responses[0] is from a list of url get requests being returned, but in this case of index 0, testing on one specific url: http://feeds.feedburner.com/marginalrevolution/feed
We were able to plug in the XML code to W3 School validator and got:
This page contains the following errors:
error on line 163 at column 31: Input is not in proper UTF-8, indicate encoding! Bytes: 0x0C 0x66 0x69 0x67
But with the ET.XMLParser(encoding='utf-8')
property, shouldn't this fix the error when parsing?