Page 1 of 1

read value from webpage and store it

Posted: 30 Apr 2019, 04:20
by automatLife84
hi to all, i have a problem. I need to copy a number inside a web page
the web page is composed in this mode:


text ...................................

text ...................................

text ...................................

NUMBER:xxxxx

other text.....


i want store the number near the text NUMBER.. I think i have to copy with ctrl+a the entire webpage text and then filter text and copy the number..
Any suggest ?

Re: read value from webpage and store it

Posted: 30 Apr 2019, 21:51
by Osprey
You could use something like the following to retrieve the actual HTML code, so that you're not doing anything visible with the browser window and don't even need to have the browser window open:

Code: Select all

ComObjError(false)
http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
( proxy && http.SetProxy(2, proxy) )
http.open( "GET", "http://www.gog.com", 1 )
http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
http.send("q=" . URIEncode(str))
http.WaitForResponse(-1)
MsgBox, % http.responsetext

URIEncode(str, encoding := "UTF-8")  {
   VarSetCapacity(var, StrPut(str, encoding))
   StrPut(str, &var, encoding)

   While code := NumGet(Var, A_Index - 1, "UChar")  {
      bool := (code > 0x7F || code < 0x30 || code = 0x3D)
      UrlStr .= bool ? "%" . Format("{:02X}", code) : Chr(code)
   }
   Return UrlStr
}
I ripped that from the GoogleTranslate.ahk script.