473,671 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stripping HTML

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?

Nov 20 '05 #1
5 2448
Public Function StripHTML(ByVal HTML As String) As String
Dim strContent As String, mString As String
Dim mStartPos As Long, mEndPos As Long
Dim i, j

strContent = HTML.Replace("</P>", vbCrLf)
strContent = strContent.Repl ace("</p>", vbCrLf)

mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Do While mStartPos <> 0 And mEndPos <> 0 And mEndPos > mStartPos
mString = Mid(strContent, mStartPos, mEndPos - mStartPos + 1)
strContent = Replace(strCont ent, mString, "")
mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Loop
strContent = Replace(strCont ent, "&nbsp;", " ")
strContent = Replace(strCont ent, "&amp;", "&")
strContent = Replace(strCont ent, "&quot;", "'")
strContent = Replace(strCont ent, "&#", "#")
strContent = Replace(strCont ent, "&lt;", "<")
strContent = Replace(strCont ent, "&gt;", ">")
strContent = Replace(strCont ent, "%20", " ")
strContent = LTrim(Trim(strC ontent))
Do While Left(strContent , 1) = Chr(13) Or Left(strContent , 1) =
Chr(10)
strContent = Mid(strContent, 2)
Loop
Return strContent.Repl ace(vbCrLf, "<br>")
End Function

"David Sawyer" <goldwings@_DEL ETE_msn.com> wrote in message
news:0e******** *************** *****@phx.gbl.. .
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?

Nov 20 '05 #2
Cor
David,
Try to use mshtml.htmldocu ment
That gives a document in "DOM" document style.
If you are used to JavaScript it is easy to get the values then to process
this with the vVB.net language.
(tagname.innert ext)
Hopes this helps a little bit,
Cor
Nov 20 '05 #3
Thanks Charles. I will put this in my program and try it
out. I appreciate your help.
-----Original Message-----
Public Function StripHTML(ByVal HTML As String) As String Dim strContent As String, mString As String
Dim mStartPos As Long, mEndPos As Long
Dim i, j

strContent = HTML.Replace("</P>", vbCrLf)
strContent = strContent.Repl ace("</p>", vbCrLf)

mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Do While mStartPos <> 0 And mEndPos <> 0 And mEndPos > mStartPos mString = Mid(strContent, mStartPos, mEndPos - mStartPos + 1) strContent = Replace(strCont ent, mString, "")
mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Loop
strContent = Replace(strCont ent, " ", " ")
strContent = Replace(strCont ent, "&", "&")
strContent = Replace(strCont ent, """, "'")
strContent = Replace(strCont ent, "&#", "#")
strContent = Replace(strCont ent, "<", "<")
strContent = Replace(strCont ent, ">", ">")
strContent = Replace(strCont ent, "%20", " ")
strContent = LTrim(Trim(strC ontent))
Do While Left(strContent , 1) = Chr(13) Or Left (strContent, 1) =Chr(10)
strContent = Mid(strContent, 2)
Loop
Return strContent.Repl ace(vbCrLf, "<br>")
End Function

"David Sawyer" <goldwings@_DEL ETE_msn.com> wrote in messagenews:0e******* *************** ******@phx.gbl. ..
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?

.

Nov 20 '05 #4
Cor
David,
You have to set the reference to Microsoft.mshtm l
You do that in the IDE by:Project, add reference, Microsoft.mshtm l(You can
do it too by right clicking on references in the soluction explorer.)
You better can not use an import when you have set a reference to this,
because then your IDE becomes terrible slow.
Use it like (as example) document as microsoft.mshtm l.document
Success
Cor
Nov 20 '05 #5
Charles,
I tried using your function by calling the function as
stripHTML(tData ToGet)
It get an invalid qualifer error in this line
strContent = HTML.Replace("</P>", vbCrLf)
And it highlights HTML.

Also on the line
Return strContent.Repl ace(vbCrLf, "<br>")
I get the error
Expected: end of statement

Any thoughts or ideas?
Thanks
-----Original Message-----
Public Function StripHTML(ByVal HTML As String) As String Dim strContent As String, mString As String
Dim mStartPos As Long, mEndPos As Long
Dim i, j

strContent = HTML.Replace("</P>", vbCrLf)
strContent = strContent.Repl ace("</p>", vbCrLf)

mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Do While mStartPos <> 0 And mEndPos <> 0 And mEndPos > mStartPos mString = Mid(strContent, mStartPos, mEndPos - mStartPos + 1) strContent = Replace(strCont ent, mString, "")
mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Loop
strContent = Replace(strCont ent, " ", " ")
strContent = Replace(strCont ent, "&", "&")
strContent = Replace(strCont ent, """, "'")
strContent = Replace(strCont ent, "&#", "#")
strContent = Replace(strCont ent, "<", "<")
strContent = Replace(strCont ent, ">", ">")
strContent = Replace(strCont ent, "%20", " ")
strContent = LTrim(Trim(strC ontent))
Do While Left(strContent , 1) = Chr(13) Or Left (strContent, 1) =Chr(10)
strContent = Mid(strContent, 2)
Loop
Return strContent.Repl ace(vbCrLf, "<br>")
End Function

"David Sawyer" <goldwings@_DEL ETE_msn.com> wrote in messagenews:0e******* *************** ******@phx.gbl. ..
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?

.

Nov 20 '05 #6

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

Similar topics

7
4995
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
1733
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
2301
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
8601
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
1254
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
6661
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...
4
4152
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
3092
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
1597
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
8401
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
8926
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...
1
8603
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,...
0
7444
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6236
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
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2818
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
2
2060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1815
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.