2014-12-01 48 views
-3

我正在嘗試在Visual Basic中構建一個程序,它對我放在我的網站上的文本做出反應。例如,該計劃進入我的學校網站,如果我的學校的網站顯示「學校已關閉」,它將在該計劃上顯示文本「No School」。Visual Basic如果網站包含某些文本

事情是這樣的:

webbrowser1.navigate("www.mysite.com") 
if <Webpage contains the words "School is Closed"> then 
    label1.text = "No School" 
end if 

我以前做過,所以我知道這是可能的,我只是不記得如何。誰能幫忙?

+0

我對'webbrowser1.navigate'不熟悉,是否將網頁返回爲字符串?此外,請標記您的編程語言(這看起來像Visual Basic給我)。 – cybermonkey 2014-12-01 19:20:36

+0

@cybermonkey是的,它是標題中所說的視覺基礎。它不必使用「webbrowser1.navigate」我只需要一些可行的東西。 – 2014-12-01 19:25:26

+0

請注意,堆棧溢出不是'爲我寫這段代碼'的網站,因此如果你被低估,不會感到驚訝。我已經提供了一個答案,請提供反饋意見,看它是否適用於您。 – cybermonkey 2014-12-01 19:30:45

回答

1

做到這一點的方法是爲本身:

Imports System.Net 
Public Class Form1 

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     Dim strin As String = New WebClient().DownloadString(("http://example.com")) 
     If strin.Contains("is closed") Then 
      Label1.Text = "School" 
     End If 
    End Sub 
End Class 

Adapted from this.

+0

該代碼讓我進一步解決我的問題,但Visual Studio給我一個錯誤的「IndexOf」。 – 2014-12-01 19:35:39

+0

@FORBIDENxKROSS我剛剛登錄到安裝了Visual Studio的筆記本電腦,一旦代碼完全工作,我會回覆您。 – cybermonkey 2014-12-01 19:36:22

+1

好的非常感謝你的時間。 – 2014-12-01 19:37:42

相關問題