SokomoKud SokomoKud - 2 months ago 25
Vb.net Question

Get string from website

Before anything, sorry for my english, I'm still learning..

For example: I want to my app to read this site and return the value after "Present Version =" and save this to a variable.

I tried some codes from here, some I just didn't understand, others I cannot can make to work.

The last question I tried:

VB.net Get text/string from html element but I didn't saw how to apply to this site.

Answer

You can achieve this by using a httpwebrequest and reading its response, then you've just got to do some string manipulation to isolate the version. Here's an example of how to use a httpwebrequest to call a web page and read its response. After that, I just split the response into lines and isolate the version from the first line. The part that actually pulls the version number out can be done a number of ways, but here's a quick example:

Dim req As HttpWebRequest = CType(WebRequest.Create("http://pastebin.com/raw/J7KF0piC"), HttpWebRequest)
Dim sr As New StreamReader(CType(req.GetResponse(), HttpWebResponse).GetResponseStream())
Dim lines() As String = sr.ReadToEnd.Split(ControlChars.CrLf.ToCharArray(),
                                           StringSplitOptions.RemoveEmptyEntries)
Dim version As String = lines(0).Substring(lines(0).IndexOf("=") + 1,
                                           lines(0).Length - lines(0).IndexOf("=") - 1).Trim
sr.Close()
MsgBox(version)