read html tag line by line and find a vlue

assuming i have
how to read line by line the index.htl and serch a vlue "TEST" in all line of documet htl, and when is found store in MY_VAR....
Who is Participating?
zzzzzoocConnect With a Mentor Commented:
You can iterate through the actual DOM but because elements have children, you may run into duplicates. The below example only outputs text from elements that 1.) have no children and 2.) have an outerText attribute. It has flaws but is just an example. Still, it's much simpler than having to parse the HTML yourself for reliable values.

'include reference to 'Microsoft HTML Object Library'
Option Explicit
Private Sub Command1_Click()
    'load DOM
    Dim doc1 As HTMLDocument
    Dim doc2 As HTMLDocument
    Set doc1 = New HTMLDocument
    Set doc2 = doc1.createDocumentFromUrl("", vbNullString)
    Do Until doc2.readyState = "complete"
    'iterate through DOM elements
    Dim obj As IHTMLElement
    For Each obj In doc2.All
        If (obj.children.length = 0) Then
            Dim txt As String
            txt = obj.getAttribute("outerText")
            If (txt <> vbNullString) Then
                Debug.Print obj.tagName, " --- ", txt
            End If
        End If
End Sub
sal21Author Commented:
hi zzzzzooc tks for code... but my rially qst is:

NOTE: in this case the value are 1, 4 and 308 but in the content of tag the value can change because the page is dinamic, in other case find the value after:

font-weight:bold">&nbsp;Pagine&nbsp;now is 1
font-weight:bold">&nbsp;Pagine&nbsp;1&nbsp;di&nbsp;now is 4
<td align="center" colspan="11" class="INFO">Totale fidi individuati:now is 308

I have this page in html...

How to find the value 1 and 4 in:

<td WIDTH="25%" ALIGN="center"><font style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight:

and to find the value 308:

<td align="center" colspan="11" class="INFO">Totale fidi individuati:

after store the value founded in var_1, var_4 and var_308

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Not sure what you want me to do when the value is found... but heres a quick function that will search a string for another string, and if it's found, will return true.

'This code requires nothing
Function IsFound(ByVal sSource As String, ByVal sFind As String, Optional ByVal CaseSensitive As Boolean = True) As Boolean
If InStr(1, IIf(CaseSensitive, sSource, LCase(sSource)), IIf(CaseSensitive, sFind, LCase(sFind))) Then IsFound = True
End Function

And a quick run-through the arguments:
sSource :: The string you want to search
sFind :: The string you want to check for
CaseSensitive :: Whether the search is case sensitive or not. If you do not specify a value it will be assumed that the search is CaseSensitive
sal21Author Commented:
hI Brownhead tks foir code....
Sorry but i would want to use in vba for excel and not rially in vb classic
hmm... I've never used VBA, but does the InStr function supported? If so, then you sould simpley say:

'This code requires nothing
If (InStr(1,String1,String2)>0) then MsgBox "Found" Else MsgBox "NotFound"

String1 :: The string you are searching
String2 :: The string you are searching for

DOes that work at all? I'm going in somewhat blind but if this doesn't work I'll try to do a little googling :D
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.