parse section of html file with visual basic .net

I have a long htm file and I'm trying to get a small section of it.  Below is part of the file.  I want to find and grab "this is what I want to grab, but the data can change".  The text before/after it will.  How can I do that?

<tr><td>&nbsp;</td></tr>
         <tr> <TD align="center" COLSPAN=6 style="background-color:#FFFFFF">
                  <div style="background-color:b9d2ff; font-weight:bolder; color:#980000; font-size: 15px">Additional My IP Information - My IP Location Lookup</div>
                </td>
              </tr>
              <tr><td>
                    <table>
                          <tr><td>&nbsp;</td></tr>
                          <tr>
                                <TD width="100%" align='left' valign='top' class="slova">
                                <!--IP Location Code to trace address begin -->
<b>My IP Country Name</b>:&nbsp;&nbsp;<font color='#980000'> United States</font>&nbsp;&nbsp;<img src='images/cflags/us.png'><br><strong>My IP Country Continent</strong>: <font color='#980000'>North America</font>
 <font color='#980000'>(NA)</font>
<br><strong>My IP Country Latitude</strong>: (38)
<br><strong>My IP Country Longitude</strong>: (-98)
<br><b>My IP Country Code</b>:&nbsp;&nbsp;USA&nbsp;&nbsp;(US)<br><br><strong>My IP Address Region</strong>: <font color='#980000'>IL</font>
<br><b>My IP Address City</b>:&nbsp;&nbsp; <font color='#980000'>Chicago</font><br><b>IP Postal Code (IP Zip Code)</b>:&nbsp;&nbsp; <font color='#980000'>63333</font><br /><b>IP Area Code</b>:&nbsp;&nbsp; <font color='#980000'>999</font><br /><b>My IP Address Latitude</b>: (31.71)<br><b>My IP Address Longtitude</b>: (-93.5016)<br><br><strong>My ISP (Internet Service Provider)</strong>:&nbsp;<font color='#980000'> this is what I want to grab, but the data can change</font><br />
<strong>My IP Address lookup</strong> for <b>166.233.222.3</b> show IP which belongs to:&nbsp;<font color='#980000'>more copmany info</font><br />
<b>My Time zone</b>: America/Chicago<br><b>My Local time</b>:<span id=localTime>America/Chicago</span><br></TD>
</TR>
chadmanvbAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robberbaron (robr)Commented:
you will need to have some consistent text,
Do you have control of the source HTML ? if so, I have used html comments as placeholders.

<br><strong>My ISP (Internet Service Provider)</strong>:&nbsp;<font color='#980000'> this is what I want to grab, but the data can change</font><br />
<strong>My IP Address lookup</strong> for <b>166.233.222.3</b> show IP which belongs to:&nbsp;<font

do the parts in bold always exist in the response ?
0
chadmanvbAuthor Commented:
Sorry, I cant control the source and have to work with what I have.  The bold should be the same every time.
0
Robberbaron (robr)Commented:
then you can grab the html file and search it for the bolded substrings.

that way you can isolate the desired text.

my test code attached.
        Dim Sep1 As String = "<strong>My ISP (Internet Service Provider)</strong>"
        Dim Sep2 As String = "<strong>My IP Address lookup</strong>"

        Dim usefulText As String = ""

        Dim fnd1 As Integer = InStr(testHTML, Sep1)
        Dim fnd2 As Integer = -1
        If fnd1 > 0 Then
            'we have found the first tag
            fnd2 = InStr(fnd1, testHTML, Sep2)

            If fnd2 > 0 Then
                'found useful text
                usefulText = testHTML.Substring(fnd1 + Sep1.Length, fnd2 - fnd1 - Sep1.Length - 1)
            End If
        End If

Open in new window

Imports System.Xml
Imports System.Xml.Linq

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim testHTML As String = <![CDATA[
<tr><td>&nbsp;</td></tr>
         <tr> <TD align="center" COLSPAN=6 style="background-color:#FFFFFF">
                  <div style="background-color:b9d2ff; font-weight:bolder; color:#980000; font-size: 15px">Additional My IP Information - My IP Location Lookup</div>
                </td>
              </tr>
              <tr><td> 
                    <table> 
                          <tr><td>&nbsp;</td></tr>
                          <tr> 
                                <TD width="100%" align='left' valign='top' class="slova">
                                <!--IP Location Code to trace address begin -->
<b>My IP Country Name</b>:&nbsp;&nbsp;<font color='#980000'> United States</font>&nbsp;&nbsp;<img src='images/cflags/us.png'><br><strong>My IP Country Continent</strong>: <font color='#980000'>North America</font>
 <font color='#980000'>(NA)</font>
<br><strong>My IP Country Latitude</strong>: (38)
<br><strong>My IP Country Longitude</strong>: (-98)
<br><b>My IP Country Code</b>:&nbsp;&nbsp;USA&nbsp;&nbsp;(US)<br><br><strong>My IP Address Region</strong>: <font color='#980000'>IL</font>
<br><b>My IP Address City</b>:&nbsp;&nbsp; <font color='#980000'>Chicago</font><br><b>IP Postal Code (IP Zip Code)</b>:&nbsp;&nbsp; <font color='#980000'>63333</font><br /><b>IP Area Code</b>:&nbsp;&nbsp; <font color='#980000'>999</font><br /><b>My IP Address Latitude</b>: (31.71)<br><b>My IP Address Longtitude</b>: (-93.5016)<br><br><strong>My ISP (Internet Service Provider)</strong>:&nbsp;<font color='#980000'> this is what I want to grab, but the data can change</font><br />
<strong>My IP Address lookup</strong> for <b>166.233.222.3</b> show IP which belongs to:&nbsp;<font color='#980000'>more copmany info</font><br />
<b>My Time zone</b>: America/Chicago<br><b>My Local time</b>:<span id=localTime>America/Chicago</span><br></TD>
</TR>]]>.Value

        Dim Sep1 As String = "<strong>My ISP (Internet Service Provider)</strong>"
        Dim Sep2 As String = "<strong>My IP Address lookup</strong>"

        Dim usefulText As String = ""

        Dim fnd1 As Integer = InStr(testHTML, Sep1)
        Dim fnd2 As Integer = -1
        If fnd1 > 0 Then
            'we have found the first tag
            fnd2 = InStr(fnd1, testHTML, Sep2)

            If fnd2 > 0 Then
                'found useful text
                usefulText = testHTML.Substring(fnd1 + Sep1.Length, fnd2 - fnd1 - Sep1.Length - 1)
            End If
        End If

    End Sub
End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chadmanvbAuthor Commented:
Thanks so much!  you solution worked great.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.