2012-08-16 66 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