使用Gambas,可以将网页下载为字符串,然后解析该字符串。我知道一旦我有了数据,我就可以解析字符串中的数据,我正在努力将网页中的数据转换为字符串。
发布于 2016-07-25 05:33:15
您可以使用gb.net.curl组件中的HttpClient类
在那里,您还可以找到一个如何同步或异步读取数据的示例。
要从web获取字符串形式的数据,您可以编写以下函数(在本例中它将是同步的)
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")
Endhttps://stackoverflow.com/questions/38550405
复制相似问题