473,748 Members | 9,596 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stripping html

I understand that you can strip html out of a txt file so that all the
information is left is the visable information that is needed (e.g.
everything that has < > around is gone). My question is that I have a
table of information that I need to be fed into a program as such. Well
kind of I need the program to read it just as you would on paper and be
able to use that information like it was entered. I am unsure how strip
so much away just to leave me with the information I want and then use
it like I want. Any help?

Jun 12 '06 #1
6 3080
Medros (in 11************* *********@j55g2 00...legr oups.com)
said:

| I understand that you can strip html out of a txt file so that all
| the information is left is the visable information that is needed
| (e.g. everything that has < > around is gone). My question is that
| I have a table of information that I need to be fed into a program
| as such. Well kind of I need the program to read it just as you
| would on paper and be able to use that information like it was
| entered. I am unsure how strip so much away just to leave me with
| the information I want and then use it like I want. Any help?

Start with a simple program that reads and saves one character at a
time looking for a '<' character. When it finds a '<', it should throw
it (and following characters) away until it finds a '>'. When the
program reaches end-of-file, hopefully it's saved what you want to
keep.

You'll probably discover that you want to add refinements (perhaps to
deal with HTML encodings like &nbsp; and &lt; - but those can wait on
getting the initial version working.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Jun 12 '06 #2
Medros said:
I understand that you can strip html out of a txt file so that all the
information is left is the visable information that is needed (e.g.
everything that has < > around is gone). My question is that I have a
table of information that I need to be fed into a program as such. Well
kind of I need the program to read it just as you would on paper and be
able to use that information like it was entered. I am unsure how strip
so much away just to leave me with the information I want and then use
it like I want. Any help?


If the HTML is well-produced, mostly you can simply read characters one by
one. If you hit a '<' character, discard it, and keep discarding everything
until you hit a '>', which again you can discard.

If you hit a & character, though, you have some work to do. You'll need to
save up characters until you hit a semicolon.

The characters between the & and the ; form a keyword, e.g. &amp; for
ampersand, &lt; for '<', &gt; for '>', &copy; for the copyright symbol, and
so on. You will need to have some kind of lookup in your program for
matching these keywords with their replacements.

If you hit a space character, preserve it, but then discard all remaining
whitespace until the next non-whitespace character.

These simple rules will give you a basic translation into English, but you
have to be a bit cleverer if you want to split text into paragraphs and so
on, by interpreting tags such as <BR>, <P>, <TD> etc -- at which point you
won't be too far away from having your own text-only but otherwise
full-blown HTML renderer.

If the HTML is /not/ well-produced, the above may not be sufficient.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jun 12 '06 #3
On Sun, 11 Jun 2006 21:46:03 -0500, "Morris Dovey" <mr*****@iedu.c om>
wrote:
Medros (in 11************* *********@j55g2 00...legr oups.com)
said:

| I understand that you can strip html out of a txt file so that all
| the information is left is the visable information that is needed
| (e.g. everything that has < > around is gone). My question is that
| I have a table of information that I need to be fed into a program
| as such. Well kind of I need the program to read it just as you
| would on paper and be able to use that information like it was
| entered. I am unsure how strip so much away just to leave me with
| the information I want and then use it like I want. Any help?

Start with a simple program that reads and saves one character at a
time looking for a '<' character. When it finds a '<', it should throw
it (and following characters) away until it finds a '>'. When the
program reaches end-of-file, hopefully it's saved what you want to
keep.

I remember starting with a simple program like that, and finding to my
dismay that between the "script" and "/script" tags the '<' and '>'
characters are used not as tag delimiters but as "greater than" and
"less than" comparison operators. I had to check for those particular
tags and discard everything between them, and not let the presence of
a lone unbalanced '<' in the script cause my logic to miss finding the
"/string" tag.

Bill

Jun 12 '06 #4
Bill Latvin (in 44************* ****@news.veriz on.net) said:

| On Sun, 11 Jun 2006 21:46:03 -0500, "Morris Dovey"
| <mr*****@iedu.c om> wrote:
|
|| Medros (in 11************* *********@j55g2 00...legr oups.com)
|| said:
||
||| I understand that you can strip html out of a txt file so that all
||| the information is left is the visable information that is needed
||| (e.g. everything that has < > around is gone). My question is that
||| I have a table of information that I need to be fed into a program
||| as such. Well kind of I need the program to read it just as you
||| would on paper and be able to use that information like it was
||| entered. I am unsure how strip so much away just to leave me with
||| the information I want and then use it like I want. Any help?
||
|| Start with a simple program that reads and saves one character at a
|| time looking for a '<' character. When it finds a '<', it should
|| throw it (and following characters) away until it finds a '>'.
|| When the program reaches end-of-file, hopefully it's saved what
|| you want to keep.
||
| I remember starting with a simple program like that, and finding to
| my dismay that between the "script" and "/script" tags the '<' and
| '>' characters are used not as tag delimiters but as "greater than"
| and "less than" comparison operators. I had to check for those
| particular tags and discard everything between them, and not let
| the presence of a lone unbalanced '<' in the script cause my logic
| to miss finding the "/string" tag.

Welcome to the club. It's because of things like that that I added my
second paragraph:

"You'll probably discover that you want to add refinements (perhaps to
deal with HTML encodings like &nbsp; and &lt; - but those can wait on
getting the initial version working."

The refinements will depend on whether the OP wants a general solution
or just enough to extract data from one particular page. On
re-reading, I'd guess is that <table>, <tr>, and <td> tags may be his
1st refinement - but the question indicated that he'll probably need
to start at the most basic level.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Jun 12 '06 #5
Richard Heathfield wrote:
Medros said:

I understand that you can strip html out of a txt file so that all the
information is left is the visable information that is needed (e.g.
everything that has < > around is gone). My question is that I have a
table of information that I need to be fed into a program as such. Well
kind of I need the program to read it just as you would on paper and be
able to use that information like it was entered. I am unsure how strip
so much away just to leave me with the information I want and then use
it like I want. Any help?

If the HTML is well-produced, mostly you can simply read characters one by
one. If you hit a '<' character, discard it, and keep discarding everything
until you hit a '>', which again you can discard.

If you hit a & character, though, you have some work to do. You'll need to
save up characters until you hit a semicolon.

The characters between the & and the ; form a keyword, e.g. &amp; for
ampersand, &lt; for '<', &gt; for '>', &copy; for the copyright symbol, and
so on. You will need to have some kind of lookup in your program for
matching these keywords with their replacements.

If you hit a space character, preserve it, but then discard all remaining
whitespace until the next non-whitespace character.

These simple rules will give you a basic translation into English, but you
have to be a bit cleverer if you want to split text into paragraphs and so
on, by interpreting tags such as <BR>, <P>, <TD> etc -- at which point you
won't be too far away from having your own text-only but otherwise
full-blown HTML renderer.

If the HTML is /not/ well-produced, the above may not be sufficient.

HTMLtidy (http://tidy.sourceforge.net/) is your friend in this cases.
This little program has prevented much pain and suffering!

--
Ian Collins.
Jun 12 '06 #6
"Medros" <Me********@gma il.com> writes:
I understand that you can strip html out of a txt file so that all the
information is left is the visable information that is needed (e.g.
everything that has < > around is gone). My question is that I have a
table of information that I need to be fed into a program as such. Well
kind of I need the program to read it just as you would on paper and be
able to use that information like it was entered. I am unsure how strip
so much away just to leave me with the information I want and then use
it like I want. Any help?


lynx -dump ?

Asbjørn
Jun 12 '06 #7

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

Similar topics

7
4997
by: Margaret MacDonald | last post by:
I've been going mad trying to figure out how to do this--it should be easy! Allow the user to enter '\_sometext\_', i.e., literal backslash, underscore, some text, literal backslash, underscore and, after submitting via POST to a preg_replace filter, get back '_sometext_' (i.e., the same thing with the literal backslashes stripped)
3
1737
by: Steveo | last post by:
I am currently stripping HTML from a string with the following code. (I know it's not the best way to strip HTML but bear with me) re.compile("<.*?>") I wanted to allow all H1 and H2 tags so i changed it to: re.compile("<*?>") This seemed to work but it also allowed the HTML tag(basically anythin
2
2317
by: Patrick | last post by:
Hello, after learning that I was taking a class in VB.NET, I have been drafted to solve all my companies VB/scripting problems - hey, I should know everything; I've already taken 6 classes ;) I should have been quiet about it, but then I would never be reimbursed. Oh well. I have been asked to write a program to ping a NetBIOS name, get the IP, and compare the 3rd octet to a list to get the computer's location. So far, I can ping the IP,...
258
8699
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
4
1262
by: Lance | last post by:
Hi, What way could I strip certain tags (like HTML comments) from the HTML being delivered to the client? I don't mean what regexp to use, but where do I put this stripping code? I'm thinking something in the Global.asax, but I can't find any reference to it having a Render or PreRender event or how to tie into them if I did! I'd ideally like some help along the lines of: 1 - Where to put the code 2 - example of how to alter the...
4
6674
by: Lu | last post by:
Hi, i am currently working on ASP.Net v1.0 and is encountering the following problem. In javascript, I'm passing in: "somepage.aspx?QSParameter=<RowID>Chèques</RowID>" as part of the query string. However, in the code behind when I tried to get the query string value by calling Request.QueryString("QSParameter"), the value I got is: "<RowID>Chques</RowID>". The special character "è" has been stripped out. The web.config file is...
5
2457
by: David Sawyer | last post by:
I am trying to read in an HTML file and strip out the HTML code so that all I have left is the text of the body. Does anyone have any suggestions for doing this? Any HTML stripping routines or objects that perform the function?
4
4171
by: Spondishy | last post by:
Hi, I'm looking for help with a regular expression and c#. I want to remove all tags from a piece of html except the following. <a> <b> <h1> <h2>
7
3094
by: FFMG | last post by:
Hi, I have a form that allows users to comment, add entries and so on. But what a lot of them do is copy and paste directly from MS Word to my forms. almost all browsers will accept the post and give the impression that everything is saved properly. But, that is not the case when it comes time to displaying the message
3
1600
by: Michel Bouwmans | last post by:
Hey everyone, I'm trying to strip all script-blocks from a HTML-file using regex. I tried the following in Python: testfile = open('testfile') testhtml = testfile.read() regex = re.compile('<script\b*>(.*?)</script>', re.DOTALL) result = regex.sub('', blaat)
0
8991
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
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
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
9370
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
9321
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
6796
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
4602
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...
1
3312
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
2215
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.