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 6137033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:40:37+00:00 2026-05-23T17:40:37+00:00

This portion of code parses XML for output to the screen on a webpage.

  • 0

This portion of code parses XML for output to the screen on a webpage.

for counter in range(100):
    try:
        for item in BlekkoSearchResultsXML.getElementsByTagName('item'):
            Blekko_PageTitle = item.getElementsByTagName('title')[counter].firstChild.toxml(encoding="utf-8")
            Blekko_PageDesc = item.getElementsByTagName('description')[counter].firstChild.toxml(encoding="utf-8")
            Blekko_DisplayURL = item.getElementsByTagName('guid')[counter].firstChild.toxml(encoding="utf-8")
            Blekko_URL = item.getElementsByTagName('link')[counter].firstChild.toxml(encoding="utf-8")
            print "<h2>" + Blekko_PageTitle + "</h2>"
            print Blekko_PageDesc + "<br />"
            print Blekko_DisplayURL + "<br />"
            print Blekko_URL + "<br />"
    except IndexError:
        break

However, the script fails if it encounters a set of null XML tags, i.e. if a page had no page title or description, with the error message:

AttributeError: 'NoneType' object has no attribute 'toxml' 
      args = ("'NoneType' object has no attribute 'toxml'",)

Snippet of XML being parsed:

<item>
        <title>SUSHI FANLISTING</title>
        <link>http://sushi.perfectdrug.net/</link>
        <guid>http://sushi.perfectdrug.net/</guid>
        <description>This is the official...</description>
        </item>

I have unsuccessfully tried using a try/except statement like this:

try:
    Blekko_PageTitle = item.getElementsByTagName('title')[counter].firstChild.toxml(encoding="utf-8")
except Blekko_PageTitle = None:
    Blekko_PageTitle = "No page title provided..."

Any suggestions appreciated.

  • 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-23T17:40:37+00:00Added an answer on May 23, 2026 at 5:40 pm

    You’re doing except wrong: it catches Exception objects that get raised. You want

    except AttributeError:
    

    Alternatively, use a conditional:

    if Blekko_PageTitle = None:
        ...
    else:
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone explain to me what this portion of code means? repeat scroll 0
following up from yesterday... This portion of the code does work. $(document).ready(function(){ $('#listMenu a').click(function
Let's say we have a code portion like this: IProduct product = ProductCreator.CreateProduct(); //Factory
I'm looking through some code for learning purposes. I'm working through this portion of
i don't understand how this happen. This is portion of my code.. int isGoal(Node
I needed some help in trying to optimize this code portion ... Basically here's
This is the portion of code surrounding the issue function twitter_count($twitter_id, $widget_id, $clear_cache) {
this portion of code is outputing 01/01/1970. is my code incorrect? i have only
I have this loop that parses machine code and emulates the instructions as if
I have an html page i want to print a portion of this html

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.