The below code returns the top Google result for a keyword, in JSON format.
How can I extract the URL from that JSON result?
Thanks!
Code: Select all
Procedure.s GetHTTPText(URL$, TimeOut=5000)
Protected BufferSize = $1000, *Buffer = AllocateMemory(BufferSize)
Protected ServerName$ = GetURLPart(URL$, #PB_URL_Site)
Protected ConnectionID = OpenNetworkConnection(ServerName$, 80)
If ConnectionID
SendNetworkString(ConnectionID, "GET "+URL$+" HTTP/1.0" +#LFCR$+#LFCR$)
Time = ElapsedMilliseconds()
Repeat
Delay(10)
Event = NetworkClientEvent(ConnectionID)
If Event = #PB_NetworkEvent_Data
Repeat
Size = ReceiveNetworkData(ConnectionID, *Buffer, BufferSize)
String$ + PeekS(*Buffer, Size, #PB_Ascii)
Until Not Size
Inhalt = FindString(String$, #LFCR$, 1)
If Inhalt
String$ = Mid(String$, Inhalt+3)
EndIf
EndIf
Until ElapsedMilliseconds()-Time > TimeOut Or String$
CloseNetworkConnection(ConnectionID)
EndIf
FreeMemory(*Buffer)
ProcedureReturn String$
EndProcedure
InitNetwork()
S$ = GetHTTPText("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=1&q=alcatraz" )
Debug S$
ParseJSON(1, S$)
Debug JSONType(JSONValue(1))