473,408 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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 9328
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AdamD | last post by:
Does anyone have an example of how to strip HTML tags from an laready existing text file Thanks
1
by: John Grandy | last post by:
Let's say I'm writing an app where various 3rd parties provide content. In code, I store their content in strings. The content typically is plain text , but some providers add-in snippets of...
2
by: Daniel M. Hendricks | last post by:
I'm looking for a function/regex in C# to strip unwanted HTML tags from comments posted to my web site. Previously, it was written in PHP and I used this function to strip unwanted tags: ...
3
by: Danny | last post by:
Hallo, all I have used this function. $string = strip_tags($p1,'<i><b><u><br><p><font>'); The problem is that the title will be printed as well, but i dont allow the title tag. How to i...
2
by: tshad | last post by:
Is there an easy way to strip HTML tags from Text to get just the plain text? I am using a program called FreeTextBox that lets you format Text in a TextBox. It does this by adding HTML tags...
4
by: Nathan Sokalski | last post by:
I have two asp:ImageMaps in a table cell as follows: <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr valign="top"> <td align="center"> <asp:ImageMap ID="mapBanner"...
4
by: Steve | last post by:
Hi, I'm a complete PHP n00b slowly finding my way around I'm using the following function that I found on php.net to strip out html and return only the text. It works well except for when you...
3
by: Simon | last post by:
Hi We have an application that needs to just get the text that you would 'see' when you open a webpage in Internet Explorer with no code. Is it possible to strip out the html tags from the...
6
by: george | last post by:
hello, which is the best way to strip jscript/vbscript from user input? Is there any module I could reuse? thanks in advance george P.S. the solution must allow users to enter html code.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.