2016-07-24 70 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