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? 5 2428
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.Replace("</p>", vbCrLf)
mStartPos = InStr(strContent, "<")
mEndPos = InStr(strContent, ">")
Do While mStartPos <> 0 And mEndPos <> 0 And mEndPos > mStartPos
mString = Mid(strContent, mStartPos, mEndPos - mStartPos + 1)
strContent = Replace(strContent, mString, "")
mStartPos = InStr(strContent, "<")
mEndPos = InStr(strContent, ">")
Loop
strContent = Replace(strContent, " ", " ")
strContent = Replace(strContent, "&", "&")
strContent = Replace(strContent, """, "'")
strContent = Replace(strContent, "&#", "#")
strContent = Replace(strContent, "<", "<")
strContent = Replace(strContent, ">", ">")
strContent = Replace(strContent, "%20", " ")
strContent = LTrim(Trim(strContent))
Do While Left(strContent, 1) = Chr(13) Or Left(strContent, 1) =
Chr(10)
strContent = Mid(strContent, 2)
Loop
Return strContent.Replace(vbCrLf, "<br>")
End Function
"David Sawyer" <goldwings@_DELETE_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?
David,
Try to use mshtml.htmldocument
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.innertext)
Hopes this helps a little bit,
Cor
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.Replace("</p>", vbCrLf)
mStartPos = InStr(strContent, "<") mEndPos = InStr(strContent, ">") Do While mStartPos <> 0 And mEndPos <> 0 And
mEndPos > mStartPos mString = Mid(strContent, mStartPos, mEndPos -
mStartPos + 1) strContent = Replace(strContent, mString, "") mStartPos = InStr(strContent, "<") mEndPos = InStr(strContent, ">") Loop strContent = Replace(strContent, " ", " ") strContent = Replace(strContent, "&", "&") strContent = Replace(strContent, """, "'") strContent = Replace(strContent, "&#", "#") strContent = Replace(strContent, "<", "<") strContent = Replace(strContent, ">", ">") strContent = Replace(strContent, "%20", " ") strContent = LTrim(Trim(strContent)) Do While Left(strContent, 1) = Chr(13) Or Left
(strContent, 1) =Chr(10) strContent = Mid(strContent, 2) Loop Return strContent.Replace(vbCrLf, "<br>") End Function
"David Sawyer" <goldwings@_DELETE_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?
.
David,
You have to set the reference to Microsoft.mshtml
You do that in the IDE by:Project, add reference, Microsoft.mshtml(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.mshtml.document
Success
Cor
Charles,
I tried using your function by calling the function as
stripHTML(tDataToGet)
It get an invalid qualifer error in this line
strContent = HTML.Replace("</P>", vbCrLf)
And it highlights HTML.
Also on the line
Return strContent.Replace(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.Replace("</p>", vbCrLf)
mStartPos = InStr(strContent, "<") mEndPos = InStr(strContent, ">") Do While mStartPos <> 0 And mEndPos <> 0 And
mEndPos > mStartPos mString = Mid(strContent, mStartPos, mEndPos -
mStartPos + 1) strContent = Replace(strContent, mString, "") mStartPos = InStr(strContent, "<") mEndPos = InStr(strContent, ">") Loop strContent = Replace(strContent, " ", " ") strContent = Replace(strContent, "&", "&") strContent = Replace(strContent, """, "'") strContent = Replace(strContent, "&#", "#") strContent = Replace(strContent, "<", "<") strContent = Replace(strContent, ">", ">") strContent = Replace(strContent, "%20", " ") strContent = LTrim(Trim(strContent)) Do While Left(strContent, 1) = Chr(13) Or Left
(strContent, 1) =Chr(10) strContent = Mid(strContent, 2) Loop Return strContent.Replace(vbCrLf, "<br>") End Function
"David Sawyer" <goldwings@_DELETE_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?
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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;
|
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...
|
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...
|
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>
|
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...
|
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 =...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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...
| |