Strip HTML tags?

F

Fazer

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

BW Glitch

Fazer said:
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/Cookbook/Python/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"
 
F

Fredrik Lundh

L

Lothar Scholz

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

Fazer

BW Glitch said:
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/Cookbook/Python/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.
 
B

BW Glitch

Fazer said:
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"
 
F

Fazer

BW Glitch said:
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.
 
B

BW Glitch

Fazer said:
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)
 
F

Fazer

BW Glitch said:
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,

Ahh...thanks a lot! I get it know.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top