2014-06-27 39 views
0

我正在尋找僅從本網站提取開始「A SUNOT ...」的行。 https://pilotweb.nas.faa.gov/common/nat.html從網頁中提取單行VB2008

然後我想將該行粘貼到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命令是否適合在那裏使用。

謝謝,詹姆斯

+0

你可能要考慮使用WebBrowser控件 - 它是刮應用程序更加容易。 –

+0

謝謝,我會做 – user3772670

回答

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 
+0

非常棒,謝謝你,這是一種享受! – user3772670

+0

我現在唯一的問題是對於C - RESNO,頁面上有另一個「C」實例,因爲RESNO可能會改變,是否有一種方法可以選擇這一行,而不管「C」後面是什麼? – user3772670

+0

因爲在「C」之前總會有一個vbLf,所以可以使用下面的StartIndex代替Dim StartIndex As Integer = ContentStr.IndexOf(vbLf&「C」)+ 1 –