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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:42:53+00:00 2026-06-03T02:42:53+00:00

Okay, the Title is a bit vague, but what I’m trying to do is

  • 0

Okay, the Title is a bit vague, but what I’m trying to do is download data online, parse it and then put the parsed ‘data’ into an excel file.

I’m getting stuck in trying to put the data into a vector or list. Note that, the data can be either words or numbers. Also, I the length of the data is unknown. I tried the code below:

class MyHTMLParser(HTMLParser):
    def handle_data(self, data):
        d=[]
        d=d.append(data)

parser = MyHTMLParser()
parser.feed('<html><head><title>Test</title></head>'
            '<body><h1>Parse me!</h1></body></html>')

d

Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
d
NameError: name 'd' is not defined

I looked around the forum for an answer, but didn’t seem to encounter anything. I am a beginner, so may I’m missing something basic? Thanks, for the help…

  • 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-03T02:42:55+00:00Added an answer on June 3, 2026 at 2:42 am

    There are three problems with your code.

    • You are creating a new empty list every time you call the method.
    • list.append returns None (not the list) so your list that now contains one element is not actually stored anywhere.
    • Assigning to a variable inside a function creates a local variable, not a global variable (unless you specify that the variable should be global with the global keyword).

    Try this instead:

    d = []
    
    class MyHTMLParser(HTMLParser):
        def handle_data(self, data):
            d.append(data)
    

    It’s also a bad style to use global variable. You might want to consider making d an attribute of the class, and giving it a better name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so I know the title is very vague but here is my more
Okay so the title might sound a bit confusing, but here's what I want
Okay the title may not justify what I'm trying to do here but dont
Okay so the title may be a bit misleading. What I am trying to
Okay, I feel a bit foolish for having to ask this but I guess
Okay so my title might be a little confusing, but let me explain my
You read the title and groaned. That's okay. I did too. But we do
Okay so in my data base i have the following columns: id , title
okay, my problem is a little bit more difficult than the title would tell...
Okay, the title of this topic is really stupid - but I am not

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.