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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:02:31+00:00 2026-06-06T02:02:31+00:00

I have been using HTML Parser to scrapping data from websites and stripping html

  • 0

I have been using HTML Parser to scrapping data from websites and stripping html coding whilst doing so. I’m aware of various modules such as Beautiful Soup, but decided to go down the path of not depending on “outside” modules. There is a code code supplied by Eloff: Strip HTML from strings in Python

from HTMLParser import HTMLParser

class MLStripper(HTMLParser):
    def __init__(self):
        self.reset()
        self.fed = []
    def handle_data(self, d):
        self.fed.append(d)
    def get_data(self):
        return ''.join(self.fed)

def strip_tags(html):
    s = MLStripper()
    s.feed(html)
    return s.get_data()

It works in Python 3.1. However, I recently upgraded to Python 3.2.x and have found I get errors regarding the HTML Parser code as written above.

My first error points to the line:

s.feed(html)

… and the error says …

AttributeError: 'MLStripper' object has no attribute 'strict'

So, after a bit of research, I add “strict=True” to the top line, making it…

class MLStripper(HTMLParser, strict=True)

However, I get the new error of:

TypeError: type() takes 1 or 3 arguments

To see what would happen, I removed the “self” argument and left in the “strict=True”… which gave up the error:

NameError: global name 'self' is not defined

… and I got the “I’m guessing on guesses” feeling.

I have no idea what the third argument in the class MLStripper(HTMLParser) line would be, after self and strict=True; research didn’t toss any enlightenment.

  • 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-06T02:02:34+00:00Added an answer on June 6, 2026 at 2:02 am

    You’re subclassing HTMLParser, but you aren’t calling its __init__ method. You need to add one line to your __init__ method:

    def __init__(self):
        super().__init__()
        self.reset()
        self.fed = []
    

    Also, for Python 3, the import line is:

    from html.parser import HTMLParser
    

    With these changes, a simple example works. Don’t change the class line, that’s not related.

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

Sidebar

Related Questions

I have been using Sandcastle Help File Builder to produce help files (HTML 1.0)
I have been using a product which displays parsed XML files as HTML. It
Im trying to append some JSON data from the last.fm API, I have been
Im trying to append some JSON data from the last.fm API, I have been
for a while I've been using the simple_html_dom include, but I have a question.
I have been using Visual Studio integrated with Source Safe for years, when I
I have been using this code with great success to pull out the first
I have been using the CodeIgniter system for a while now - but it
I have been using a noscript tag to show a warning when users have
I have been using WPF for a few years now and don't have any

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.