Read web responses to see if they contain a given text

1

I am trying to read web pages, for example I would like to detect the string "My server" in the answer.

I found this:

Dim Str As System.IO.Stream
Dim srRead As System.IO.StreamReader
Try
' make a Web request
Dim req As System.Net.WebRequest = System.Net.WebRequest.Create("http://localhost/quietoputo")
Dim resp As System.Net.WebResponse = req.GetResponse
StR = resp.GetResponseStream
srRead = New System.IO.StreamReader(Str)
' read all the text 
RichTextBox1.Text = srRead.ReadToEnd
Catch ex As Exception
RichTextBox1.Text = "Unable to download content"
Finally
' Close Stream and StreamReader when done
srRead.Close()
Str.Close()
End Try

If we enter the web we simply see a title "My server:" followed by another title with the IP. My intention is to detect if the web I have visited has the string "My server:" and save the IP in a textbox or variable or whatever.

How could I do it?

    
asked by Adrian Hernando Solanas 15.06.2018 в 10:27
source

1 answer

3

You should simply put the text in a variable string instead of RichTextBox :

Dim texto as String = srRead.ReadToEnd 

and then do a text search using Contains :

IF texto.Contains("My Server")..
    
answered by 20.06.2018 / 13:57
source