469,282 Members | 1,732 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Strip HTML tags?

Hello,

I was wondering what would be the easiest way to strip away HTML tags from a string?

Or how would I remove everything between < and > also the < , > as well using regex?

Thanks for any help!
Jul 18 '05 #1
8 9178
Fazer wrote:
Hello,

I was wondering what would be the easiest way to strip away HTML tags from a string?

Or how would I remove everything between < and > also the < , > as well using regex?


You could use the SGMLparser for that also. Check the Python Cookbook at
ASPN ( http://aspn.activestate.com/ASPN/Python/Cookbook/ ) for a recipe
that uses it (
http://aspn.activestate.com/ASPN/Coo...n/Recipe/52281 ).

--
Glitch

-----BEGIN TF FAN CODE BLOCK-----
G+++ G1 G2+ BW++++ MW++ BM+ Rid+ Arm-- FR+ FW-
#3 D+ ADA N++ W OQP MUSH- BC- CN++ OM P75
-----END TF FAN CODE BLOCK-----

"Waspinator negative negative negative! I am Shrapnel, Decepticon
hero-o-o-o!"
"Shrapnel? That was a Decepticon from the Great War three centuries
ago! ..."
-- A loopy Waspinator and Blackarachnia, "Dark Designs"

Jul 18 '05 #2
"Fazer" <fa****@jaredweb.com> wrote:
I was wondering what would be the easiest way to strip away HTML tags from a string?

Or how would I remove everything between < and > also the < , > as well using regex?


for htmllib and sgmllib examples, see chapter 5 here:

http://effbot.org/zone/librarybook-index.htm

and the "syndication tweaks" entry on this page:

http://online.effbot.org/2003_08_01_...e.htm#20030811

for a RE-based solution, see:

http://effbot.org/zone/re-sub.htm#strip-html

</F>


Jul 18 '05 #3
fa****@jaredweb.com (Fazer) wrote in message news:<7b**************************@posting.google. com>...
Or how would I remove everything between < and > also the < , > as well using regex?


You don't want to use regex for this. regex is only for very simple
things readable. Use the HTML parser and concatenate the text you get
from there.
Jul 18 '05 #4
BW Glitch <bw******@hotpop.com> wrote in message news:<br************@ID-203388.news.uni-berlin.de>...
Fazer wrote:
Hello,

I was wondering what would be the easiest way to strip away HTML tags from a string?

Or how would I remove everything between < and > also the < , > as well using regex?


You could use the SGMLparser for that also. Check the Python Cookbook at
ASPN ( http://aspn.activestate.com/ASPN/Python/Cookbook/ ) for a recipe
that uses it (
http://aspn.activestate.com/ASPN/Coo...n/Recipe/52281 ).

--
Glitch

-----BEGIN TF FAN CODE BLOCK-----
G+++ G1 G2+ BW++++ MW++ BM+ Rid+ Arm-- FR+ FW-
#3 D+ ADA N++ W OQP MUSH- BC- CN++ OM P75
-----END TF FAN CODE BLOCK-----

"Waspinator negative negative negative! I am Shrapnel, Decepticon
hero-o-o-o!"
"Shrapnel? That was a Decepticon from the Great War three centuries
ago! ..."
-- A loopy Waspinator and Blackarachnia, "Dark Designs"


Thanks! The recipe works out fine! The problem is that I saved the
class in a file and I want it to be included in my other script. How
can that be done? My other script is in the same directory as the
class and doing import <name of class> doesn't work.

Any ideas?

Thanks.
Jul 18 '05 #5
Fazer wrote:
BW Glitch <bw******@hotpop.com> wrote in message news:<br************@ID-203388.news.uni-berlin.de>...
Fazer wrote:

Hello,

I was wondering what would be the easiest way to strip away HTML tags from a string?

Or how would I remove everything between < and > also the < , > as well using regex?


You could use the SGMLparser for that also. Check the Python Cookbook at
ASPN ( http://aspn.activestate.com/ASPN/Python/Cookbook/ ) for a recipe
that uses it (
http://aspn.activestate.com/ASPN/Coo...n/Recipe/52281 ).

Thanks! The recipe works out fine! The problem is that I saved the
class in a file and I want it to be included in my other script. How
can that be done? My other script is in the same directory as the
class and doing import <name of class> doesn't work.


You should import <filename minus .py*>

--
Glitch

-----BEGIN TF FAN CODE BLOCK-----
G+++ G1 G2+ BW++++ MW++ BM+ Rid+ Arm-- FR+ FW-
#3 D+ ADA N++ W OQP MUSH- BC- CN++ OM P75
-----END TF FAN CODE BLOCK-----

"Come on, fight back! How far will you carry this silly chivalry?
'Cause this dark damsel is not impressed!"
-- Blackarachnia to Silverbolt, "Bad Spark"
Jul 18 '05 #6
BW Glitch <bw******@hotpop.com> wrote in message news:<br************@ID-203388.news.uni-berlin.de>...
Fazer wrote:
BW Glitch <bw******@hotpop.com> wrote in message news:<br************@ID-203388.news.uni-berlin.de>...
Fazer wrote:
Hello,

I was wondering what would be the easiest way to strip away HTML tags from a string?

Or how would I remove everything between < and > also the < , > as well using regex?

You could use the SGMLparser for that also. Check the Python Cookbook at
ASPN ( http://aspn.activestate.com/ASPN/Python/Cookbook/ ) for a recipe
that uses it (
http://aspn.activestate.com/ASPN/Coo...n/Recipe/52281 ).

Thanks! The recipe works out fine! The problem is that I saved the
class in a file and I want it to be included in my other script. How
can that be done? My other script is in the same directory as the
class and doing import <name of class> doesn't work.


You should import <filename minus .py*>

--
Glitch


Thanks for the responce! I put the class and the final function in a
tags.py file. I make another script and do : "import tags"
It works, but when I try to make a new class instance, it can't seem
to find it.
Jul 18 '05 #7
Fazer wrote:
BW Glitch <bw******@hotpop.com> wrote in message news:<br************@ID-203388.news.uni-berlin.de>...
Fazer wrote:
Thanks! The recipe works out fine! The problem is that I saved the
class in a file and I want it to be included in my other script. How
can that be done? My other script is in the same directory as the
class and doing import <name of class> doesn't work.


You should import <filename minus .py*>


Thanks for the responce! I put the class and the final function in a
tags.py file. I make another script and do : "import tags"
It works, but when I try to make a new class instance, it can't seem
to find it.


There are two ways to import modules, "import module" and "from module
import *". The latter is seldom recommended.

By doing a "import module", anything inside the module must be called
like this:

### begin example
import sys

sys.exit(0)
### end example

When you do a import tags, everything inside tags must be called
tags.CLASS .

HTH,

--
Glitch

-----BEGIN TF FAN CODE BLOCK-----
G+++ G1 G2+ BW++++ MW++ BM+ Rid+ Arm-- FR+ FW-
#3 D+ ADA N++ W OQP MUSH- BC- CN++ OM P75
-----END TF FAN CODE BLOCK-----

Blackarachnia: "We're almost through."
Silverbolt: "Then ... stand back!"
Blackarachnia: "Wait. We just have to--"
[BLAM!]
Blackarachnia: "Never mind ... What is it with guys and high
explosives?"
("The Agenda" III)
Jul 18 '05 #8
BW Glitch <bw******@hotpop.com> wrote in message news:<br************@ID-203388.news.uni-berlin.de>...
Fazer wrote:
BW Glitch <bw******@hotpop.com> wrote in message news:<br************@ID-203388.news.uni-berlin.de>...
Fazer wrote:
Thanks! The recipe works out fine! The problem is that I saved the
class in a file and I want it to be included in my other script. How
can that be done? My other script is in the same directory as the
class and doing import <name of class> doesn't work.

You should import <filename minus .py*>


Thanks for the responce! I put the class and the final function in a
tags.py file. I make another script and do : "import tags"
It works, but when I try to make a new class instance, it can't seem
to find it.


There are two ways to import modules, "import module" and "from module
import *". The latter is seldom recommended.

By doing a "import module", anything inside the module must be called
like this:

### begin example
import sys

sys.exit(0)
### end example

When you do a import tags, everything inside tags must be called
tags.CLASS .

HTH,

--
Glitch


Ahh...thanks a lot! I get it know.
Jul 18 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by AdamD | last post: by
1 post views Thread by John Grandy | last post: by
2 posts views Thread by Daniel M. Hendricks | last post: by
3 posts views Thread by Danny | last post: by
2 posts views Thread by tshad | last post: by
4 posts views Thread by Nathan Sokalski | last post: by
4 posts views Thread by Steve | last post: by
6 posts views Thread by george | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.