GET value from Webpage to msgbox

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
EtniesDC
Posts: 7
Joined: 23 Dec 2018, 17:46

GET value from Webpage to msgbox

23 Dec 2018, 18:09

Hello,
please can anyone help me? I work on stats mod for game SWAT 4. What I need is get "Score" value from webpage.
URL is: https://swat4stats.com/player/2018/Spid ... 4855/coop/ - scroll down and you can see player score: 436 (today, it will be change when player will be play)
I start with:
UrlDownloadToFile, https://swat4stats.com/player/2018/Spid ... 4855/coop/, example.txt
and from here I need export only number of score (436) to msgbox.
Did anyone know how?
Thank you
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: GET value from Webpage to msgbox

24 Dec 2018, 01:28

jeeswg's Internet Explorer and HTML tutorial

Code: Select all

pwb := ComObjCreate("InternetExplorer.Application") ;create IE Object
pwb.visible:=false  ; Set the IE object to visible
pwb.Navigate("https://swat4stats.com/player/2018/SpiderMan/54855/coop/") ;Navigate to URL
while pwb.busy or pwb.ReadyState != 4 ;Wait for page to load
	Sleep, 100
;use iWB2 Learner to find element class name & index
MsgBox % pwb.document.getElementsByClassname("right")[1].innerText
live ? long & prosper : regards
teadrinker
Posts: 4335
Joined: 29 Mar 2015, 09:41
Contact:

Re: GET value from Webpage to msgbox

24 Dec 2018, 06:36

You don't need to use InternetExplorer.Application for this purpose, it's too slow and resource intensive. You could use WinHttpRequest like this:

Code: Select all

oWhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
oWhr.Open("GET", "https://swat4stats.com/player/2018/SpiderMan/54855/coop/", false)
oWhr.Send()
status := oWhr.status
if !(status = 200 || status = 304)  {
   MsgBox, Can't get info from https://swat4stats.com`nStatus: %status%
   Return
}
html := oWhr.responseText
RegExMatch(html, ">Score<.*?\K\d+", score)
MsgBox, % score
EtniesDC
Posts: 7
Joined: 23 Dec 2018, 17:46

Re: GET value from Webpage to msgbox

24 Dec 2018, 07:01

Thank you, it works perfectly.
But only one small problem. In other player ex. https://swat4stats.com/player/2018/____ ... 9140/coop/ his score is 137,610. Msgbox write only 137.
teadrinker
Posts: 4335
Joined: 29 Mar 2015, 09:41
Contact:

Re: GET value from Webpage to msgbox

24 Dec 2018, 12:57

We can change RegExMatch to read both:

Code: Select all

RegExMatch(html, ">Score<.*?\K\d+(,\d+)?", score)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: KolaBorat and 83 guests