2016-07-24 35 views
0

使用Gambas,是否可以將網頁下載到字符串,然後解析該字符串。 我知道一旦有數據,我就可以解析字符串中的數據,我正在努力從網頁獲取數據到字符串中。網站與Gambas拼寫,可能嗎?

回答

0

可以使用HttpClient類從gb.net.curl組件

在那裏,你還可以找到一個例子,如何讀取數據同步或異步的。

要想從網絡中的數據,你可以寫下面的函數的字符串(這將是在這種情況下同步)

Public Function GetTextFromUrl(url As String) As String 
    Dim client As New HttpClient As "client" 

    client.URL = url 
    client.async = False 
    client.Get() 

    ' an error occured 
    If client.Status < 0 Then 
     Return "" 
    Endif 

    ' no data available 
    If Not Lof(client) Then 
     Return "" 
    Endif 

    ' Reads the data from the server and returns it as a String 
    Return Read #client, Lof(client) 

End 

而且你可以這樣調用該函數:

Public Sub Main() 
    Print GetTextFromUrl("http://stackoverflow.com") 
End