从网页VB2008中提取一行

时间:2014-06-27 13:26:15

标签: vb.net

我希望从这个网站中仅提取开始“A SUNOT ...”的行。 https://pilotweb.nas.faa.gov/common/nat.html

然后我想将该行粘贴到VB2008中的文本框中。

我尝试使用:

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

我得到它来写整个页面,但我想要那条线。 '?'是显示ReadLine命令是否适合在那里使用。

谢谢,詹姆斯

1 个答案:

答案 0 :(得分:1)

尝试以下代码

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