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 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

I needed some help in trying to optimize this code portion ... Basically here's
I have this loop that parses machine code and emulates the instructions as if
This is the portion of code surrounding the issue function twitter_count($twitter_id, $widget_id, $clear_cache) {
This portion of code should returns the representation in LittleEndian of 10000000, then 128,
i'm using this portion of code char encrypted_text[1024]; RSA_public_encrypt(sizeof(message), message, encrypted_text, rsa, RSA_PKCS1_OAEP_PADDING); printf(encrypted
This portion of code should read in two or more numbers (main io function
I am using PHP to parse the numeric portion of the HTTP status code
i am trying to parse this xml file into an object to use the
My code portion looks like: parser.add_option(-h, --help,-?, action = help, help= Print the help
I have a portion of code for uploading text to Azure blob storage. It

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.