2012-08-16 63 views
2

我需要知道如何从VB.NET代码中复制网站的一部分(文本)。 例如,我有这个“网站”: https://www.google.ro/search?sugexp=chrome,mod=8&sourceid=chrome&ie=UTF-8&q=my+location 如何将零件复制到我的位置?从网站的一部分获取文本VB.NET

还是......我有这样的HTTP代码(我认为) - 这是一个有点复杂: http://www.google.com/ig/api?weather=Bucharest 有我想要得到的信息为今日(最小值,最大值,湿度,风等)

请帮帮我。

回答

1

考虑使用HTML Agility Pack。它提供了一种简单的方法来抓取和解析来自其他网站的数据。您应该能够使用它轻松获取所需的数据部分。

0

下载该网页,将其存储在文本框中(text1.text = Inet1.OpenURL("http://www...")或字符串。

使用vb.nets字符串处理函数从字符串中提取数据。

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

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

下面的示例代码中提取从网站的IP地址。

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