user3772670
user3772670

Reputation: 7

Extract a single line from a webpage VB2008

I'm looking to extract only the line that starts "A SUNOT..." from this website. https://pilotweb.nas.faa.gov/common/nat.html

I then want to paste that line into a text box in VB2008.

I tried using:

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim TrackA As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://pilotweb.nas.faa.gov/common/nat.html")
        Dim gather As System.Net.HttpWebResponse = TrackA.GetResponse
        Dim write As System.IO.StreamReader = New System.IO.StreamReader(gather.GetResponseStream)
        RawData.Text = write.ReadLine(?)
    End Sub
End Class

I got it to write the entire page but I wanted just that line. The '?' is to show if that ReadLine command is the right thing to be using there.

Thanks, James

Upvotes: 0

Views: 45

Answers (1)

David -
David -

Reputation: 2031

Try the following code

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim TrackA As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://pilotweb.nas.faa.gov/common/nat.html")
    Dim gather As System.Net.HttpWebResponse = TrackA.GetResponse
    Dim write As System.IO.StreamReader = New System.IO.StreamReader(gather.GetResponseStream)

    Dim ContentStr As String = write.ReadToEnd
    Dim StartIndex As Integer = ContentStr.IndexOf("A SUNOT")
    Dim StrLength As Integer = ContentStr.IndexOf(vbLf, StartIndex) - StartIndex

    RawData.Text = ContentStr.Substring(StartIndex, StrLength)
End Sub

Upvotes: 1

Related Questions