I am trying to get a web page and parse some text from it (with document.getElementById and so on). What would be best way to do it?
I could use:
First solution:
Code: Select all
url = www.google.pl ; an example
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", url, false ), whr.Send()
www := whr.ResponseText
Second solution:
Code: Select all
url = www.google.pl ; an example
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", url, false ), whr.Send()
www := whr.ResponseText
if A_LastError
www := URLDownloadToVar(sURL, "UTF-8")
; found at https://autohotkey.com/board/topic/101686-objectresponsetext-error/
URLDownloadToVar(url, Encoding = ""){
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
hObject.Open("GET",url)
hObject.Send()
If Encoding {
oADO := ComObjCreate("adodb.stream")
oADO.Type := 1
oADO.Mode := 3
oADO.Open()
oADO.Write( hObject.ResponseBody )
oADO.Position := 0
oADO.Type := 2
oADO.Charset := Encoding
return oADO.ReadText(), oADO.Close()
}
return hObject.ResponseText
}
Third solution:
Then I tried to use URLDownloadToFile but the URL should be encoded and more importantly the downloaded webpage could be in different charset and (I could be wrong) reading files in different charset could be challenging at times in AHK.
Fourth solution:
Code: Select all
IE := ComObjCreate("InternetExplorer.Application")
IE.Visible := false
url = http://www.google.pl
IE.Navigate(url)
While IE.Busy
Sleep, 10
contents := IE.document.body.outerhtml