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

  • SEARCH
  • Home
  • 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 9165597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:56:39+00:00 2026-06-17T14:56:39+00:00

I am trying to parse a solr output of the form: <doc> <str name=source>source:A</str>

  • 0

I am trying to parse a solr output of the form:

<doc>
<str name="source">source:A</str>
<str name="url">URL:A</str>
<date name="p_date">2012-09-08T10:02:01Z</date>
</doc>
<doc>
<str name="source">source:B</str>
<str name="url">URL:B</str>
<date name="p_date">2012-08-08T11:02:01Z</date>
</doc>

I am keen on using beautiful soup (versions that have BeautifulStoneSoup; I think prior to BS4) for parsing the docs.
I have used beautiful soup for HTML parsing but some how I am not able to find a effecient way to extract the contents of the tag.

I have written:

for tags in soup('doc'):
    print tags.renderContents()

I do sense that I can work my way through it forcibly to get the outputs (like say ‘soup’ing it again), but would appreciate an effecient solution to extract data.
My output required is:

source:A
URL:A
2012-09-08T10:02:01Z
source:B
URL:B
2012-08-08T11:02:01Z

Thanks

  • 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-06-17T14:56:40+00:00Added an answer on June 17, 2026 at 2:56 pm

    Use a XML parser for task instead; xml.etree.ElementTree is included with Python:

    from xml.etree import ElementTree as ET
    
    # `ET.fromstring()` expects a string containing XML to parse.
    # tree = ET.fromstring(solrdata)  
    # Use `ET.parse()` for a filename or open file object, such as returned by urllib2:
    ET.parse(urllib2.urlopen(url))
    
    for doc in tree.findall('.//doc'):
        for elem in doc:
            print elem.attrib['name'], elem.text
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to parse an html output from a url call but i found
Im trying to parse a String thats a date 2012-07-15T20:55:33+00:00, however I keep getting
I'm trying parse a html form that looks like that: <select name=country> <option value=1>Afghanistan</option>
In trying to parse a date, I have been racking my brain for hours:
I have an xml feed at this url Now im trying parse the content,
When trying to parse the method return type, method name, and parameters from the
I'm trying to parse a 7-digit number from a page's source code and the
I'm trying to parse a xml file: <?xml version=1.0?> <settings> <output>test.dat</output> <width>5</width> <depth>4</depth> <height>10</height>
Im trying to parse a Xml file from a URL, the xml is actually
I'm trying to parse a JSON string into an array reference: my $str =

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.