473,762 Members | 6,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

An example using htmllib?

Hi.

I want a routine that strips a line of html of all it's tags. e.g I want
it to turn ....

"<p><b>This is an <h1><blink>IRRI TATING</blink></h1> line of </b>text</p>"

.... into ......

"This is an IRRITATING line of text"

I've been told I should use htmllib. I've tried reading the htmllib docs
in the Library Reference, but I have to say, it just confuses me.

Does anyone know of a page that shows some simple examples of the sort of
thing I want to do?

Or, is it possible to use the example provided in the docs to achieve
this? Here's the example below ...
from HTMLParser import HTMLParser

class MyHTMLParser(HT MLParser):

def handle_starttag (self, tag, attrs):
print "Encountere d the beginning of a %s tag" % tag

def handle_endtag(s elf, tag):
print "Encountere d the end of a %s tag" % tag

Jul 18 '05 #1
1 8846
greanozone
1 New Member
I think the things you need is ''formatter module''

Look the example ''Using the formatter module convert HTML to plain text''

in the ''http://effbot.org/librarybook/formatter.htm''

good luck!!
Jul 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4316
by: KC | last post by:
I have written a parser using htmllib.HTMLParser and it functions fine unless the HTML is malformed. For example, is some instances, the provider of the HTML leaves out the <TR> tags but includes the </TR> tags. Apparently, htmllib and more likely sgmllib do not parse an end tag if a corresponding start tag was not found. Does anyone know a way to "fool" the parser into handling the end tag is a start tag was not found? Thanks,
0
1737
by: Achim Domma | last post by:
Hi, should the HTMLParser be able to handle unicode input? I get the following traceback: self.feed(self.data) File "C:\Python23\lib\sgmllib.py", line 94, in feed self.goahead(0) File "C:\Python23\lib\sgmllib.py", line 183, in goahead self.handle_entityref(name)
7
3358
by: jennyw | last post by:
I'm trying to parse a product catalog written in HTML. Some of the information I need are attributes of tags (like the product name, which is in an anchor). Some (like product description) are between tags (in the case of product description, the tag is font). To capture product descriptions, I've been using the save_bgn() and save_end() methods. But I've noticed that the result of save_end() only includes text that isn't marked up. ...
7
9290
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. # No warranty express or implied for the accuracy, fitness to purpose
0
1579
by: Morten W. Petersen | last post by:
Hi, I have an HTML page that displays some content, and a part of that content is HTML changed into regular text. The encoding of the page is UTF-8. Here's the code that makes the change (the HTML in self.contents is UTF-8 encoded): file = cStringIO.StringIO()
25
7754
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30 minutes with Python 3 times a week since, have 14 years of computing experience, 8 years in mathematical computing and 4 years in unix admin and perl, i have quickly found the official doc: http://python.org/doc/2.4.1/lib/module-gzip.html
3
2309
by: geir.smestad | last post by:
Using Ubuntu Breezy Badger 5.10. I get the following traceback: ----- Traceback (most recent call last): File "/home/geir/programmering/htmlparse/formatter.py", line 1, in -toplevel- import formatter File "/home/geir/programmering/htmlparse/formatter.py", line 2, in -toplevel- import htmllib
1
1778
by: David Bear | last post by:
I'm trying to understand how to use the HTMLParser in htmllib but I'm not seeing enough examples. I just want to grab the contents of everything enclosed in a '<body>' tag, i.e. items from where <bodybegins to where </bodyends. I start by doing class HTMLBody(HTMLParser): def __init__(self): self.contents =
1
3184
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket). The README file in the Tools/freeze directory of the Python-2.4.4 distribution says the following (and many other things): Previous versions of Freeze used a pretty simple-minded algorithm to
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9927
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5268
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3914
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.