2
for item in root.findall('./channel/item'):
    news = {}
    # iterate child elements of item
    for child in item:
        # special checking for namespace object content:media
        if child.tag == '{http://search.yahoo.com/mrss/}content':
            news['media'] = child.attrib['url']
        else:
            news[child.tag] = child.text.encode('utf8')
    newsitems.append(news)

whats the problem ?? how am i gonna solve this problem?

1
  • that's because child.text is None. Filter it out. if child.text: ... Commented Jul 26, 2017 at 9:05

1 Answer 1

3

here:

    else:
        news[child.tag] = child.text.encode('utf8')

child.text is None in some cases. So don't create the dict entry in that case, for instance like this:

    elif child.text is not None:
        news[child.tag] = child.text.encode('utf8')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.