Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:40:08+00:00 2026-05-30T06:40:08+00:00

Hia I am having problems parsing an rss feed from stackexchange in python. When

  • 0

Hia

I am having problems parsing an rss feed from stackexchange in python.
When I try to get the summary nodes, an empty list is return

I have been trying to solve this, but can’t get my head around.

Can anyone help out?
thanks
a


In [3o]: import lxml.etree, urllib2

In [31]: url_cooking = 'http://cooking.stackexchange.com/feeds' 

In [32]: cooking_content = urllib2.urlopen(url_cooking)

In [33]: cooking_parsed = lxml.etree.parse(cooking_content)

In [34]: cooking_texts = cooking_parsed.xpath('.//feed/entry/summary')

In [35]: cooking_texts
Out[35]: []

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:40:10+00:00Added an answer on May 30, 2026 at 6:40 am

    Take a look at these two versions

    import lxml.html, lxml.etree
    
    url_cooking = 'http://cooking.stackexchange.com/feeds'
    
    #lxml.etree version
    data = lxml.etree.parse(url_cooking)
    summary_nodes = data.xpath('.//feed/entry/summary')
    print('Found ' + str(len(summary_nodes)) + ' summary nodes')
    
    #lxml.html version
    data = lxml.html.parse(url_cooking)
    summary_nodes = data.xpath('.//feed/entry/summary')
    print('Found ' + str(len(summary_nodes)) + ' summary nodes')
    

    As you discovered, the second version returns no nodes, but the lxml.html version works fine. The etree version is not working because it’s expecting namespaces and the html version is working because it ignores namespaces. Part way down http://lxml.de/lxmlhtml.html, it says “The HTML parser notably ignores namespaces and some other XMLisms.”

    Note when you print the root node of the etree version (print(data.getroot())), you get something like <Element {http://www.w3.org/2005/Atom}feed at 0x22d1620>. That means it’s a feed element with a namespace of http://www.w3.org/2005/Atom. Here is a corrected version of the etree code.

    import lxml.html, lxml.etree
    
    url_cooking = 'http://cooking.stackexchange.com/feeds'
    
    ns = 'http://www.w3.org/2005/Atom'
    ns_map = {'ns': ns}
    
    data = lxml.etree.parse(url_cooking)
    summary_nodes = data.xpath('//ns:feed/ns:entry/ns:summary', namespaces=ns_map)
    print('Found ' + str(len(summary_nodes)) + ' summary nodes')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hia. I am using some round rect buttons with own images for their states.
Hia, I got a somewhat odd problem. Im using two managed Classes that relate
Hia, got a one to many relation for chars and items. one char can
Hia, I'm looking for a way to play a movie as background in portray
I am using the zend google api library to retrieve a list of event
i am following part 5 of the symblog symfony2 tutorial: http://tutorial.symblog.co.uk/docs/customising-the-view-more-with-twig.html under heading: The
I have this code: #include <iostream> using namespace std; class FooA { public: virtual
import java.io.*; import java.util.*; public class Sort { public static void main(String[] args) throws
I'm trying to convert the string 11/24/2011 @ 01:15pm to a UNIX timestamp. The
How Can I make numbering on mySQL results. I was trying to use $_SESSION[],

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.