Get text from a part of website VB.NET

7.1k Views Asked by At

I need to know how to copy a part of a website (the text) from VB.NET code. For example, I have this "site": https://www.google.ro/search?sugexp=chrome,mod=8&sourceid=chrome&ie=UTF-8&q=my+location How can I copy the part with my location?

Or...I have this http code (I think) - it's a little more complicated: http://www.google.com/ig/api?weather=Bucharest There I want to get the informations for today (Min, max, humidity, wind etc...)

Please help me.

2

There are 2 best solutions below

0
On

Download the webpage, store it in a textbox, (text1.text = Inet1.OpenURL("http://www...") or string.

Use vb.nets string manipulation functions to extract the data from the string.

http://msdn.microsoft.com/en-us/library/aa903372(v=vs.71).aspx

http://www.thevbprogrammer.com/VBNET_04/04-08-StringHandling.htm

The sample code below extracts the IP address from a website.

Option Explicit
' Add Microsoft Internet Transfer Control

Dim pubIPA As String, pos1 As Long, pos2 As Long, str As String

Private Sub Form_Load()
    str = Inet1.OpenURL("http://api.externalip.net/ip/", icString)
    pos1 = InStr(str, "var ip =")
    pos1 = InStr(pos1 + 1, str, "'", vbTextCompare) + 1
    pos2 = InStr(pos1 + 1, str, "'", vbTextCompare)
    pubIPA = Mid$(str, pos1, pos2 - pos1)
    MsgBox pubIPA, vbInformation
    Unload Me
End Sub

http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/105605a1-4d1a-4bc8-8a13-c9cc6748065e

http://www.dreamincode.net/forums/topic/95117-get-string-between-2-values/

http://www.example-code.com/vb/findSubstring.asp

http://www.dreamincode.net/forums/topic/66912-finding-a-string-within-a-string/

http://www.dotnetperls.com/indexof-vbnet

0
On

Consider working with the HTML Agility Pack. It provides an easy way to grab and parse data from other websites. You should be able to use it to easily get at the parts of data you need.