I am trying to aggregate a few youtube feeds, concatenate them, and then parse the feeds.
When I parse the individual feed on their own, I have no trouble and the code seems to work. However, when I try to aggregate the feeds as one long string and then use etree.fromstring(aggregate_partner_feed), I get an error. The error I get is ParseError: unbound prefix and the etree line (referenced earlier) is given as the error. Any advice on how to fix this?
aggregated_partners_list = [cnn, teamcoco, buzzfeed]
i = 1
number_of_partners = len(aggregated_partners_list)
aggregate_partner_feed = ''
for entry in aggregated_partners_list:
#YOUTUBE FEED
#download the file:
file = urllib2.urlopen('http://gdata.youtube.com/feeds/api/users/'+entry+'/uploads?v=2&max-results=50')
#convert to string:
data = file.read()
#close file because we dont need it anymore:
file.close()
if i == 1:
#remove ending </feed>
data = data[:-7]
if i>1 and i != number_of_partners:
data = data[data.find('<entry'):]
data = data[:-7]
#remove everything before first <entry> in the new feed and the last </entry>
#if last, then only remove everything before first <entry>
if i == number_of_partners:
data = data[data.find('<entry'):]
#append the current feed to the existing feed
aggregate_partner_feed += data
#increment the counter
i=i+1
print isinstance(data, basestring) #returns true
print isinstance(aggregate_partner_feed, basestring) #returns true
#apply the parsing to the aggregated feed
#entire feed
root = etree.fromstring(aggregate_partner_feed) #this is the line that give an error
#all entries
entries = root.findall('{http://www.w3.org/2005/Atom}entry')
#more code that seems to work...
I parsed each feed individually and then used .append instead of concatenating the strings together and then parsing.