Last active
August 29, 2015 13:57
-
-
Save TLMcode/9678656 to your computer and use it in GitHub Desktop.
GetPlayerList() function for Ex0r in #ahk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance force | |
File := A_ScriptDir "/PlayerList.txt" | |
Gui, Add, Text,, Players | |
Gui, Add, Edit, R30 w200 +ReadOnly vPlayerList | |
Gui, Add, Text,, Page Amount | |
Gui, Add, Edit, w200 +Number vcnt | |
Gui, Add, Text,, Url: | |
Gui, Add, Edit, w200 vURL, http://www.mcbans.com/ | |
Gui, Add, Button, gGetPlayers w200 h38, Get Players | |
Gui, Add, Button, gExport w200 h38, Export file to .txt | |
gui,show,w225 h610,Ex0rScraper | |
return | |
GetPlayers: | |
Gui Submit, NoHide | |
GuiControl,, PlayerList, % GetPlayerList( URL, cnt ) ; Usage:GetPlayerList( URL, HOW MANY PAGES, File *optional* ) | |
return | |
Export: | |
GuiControlGet, PlayerList, % PlayerList | |
if ( PlayerList ) | |
{ | |
FileDelete % File | |
FileAppend % PlayerList, % File | |
MsgBox,Thank You For Using The Ex0rScraper! | |
} | |
else | |
{ | |
MsgBox, 0x10, Whoops!, Sorry could not retrieve any players! | |
} | |
return | |
GuiClose: | |
ExitApp | |
GetPlayerList( url_, cnt_, file_ = "" ) | |
{ | |
FileDelete % file_ | |
; This creates the request object and sends it to the server | |
; It returns the entire HTML to ReqObject.ResponseText | |
ReqObject := ComObjCreate("WinHttp.WinHttpRequest.5.1") | |
Loop % cnt_ | |
{ | |
ReqObject.Open("Get", url_ ( a_index>1 ? A_Index : "" ) ), ReqObject.Send() | |
; This parses the HTML, finds and matches the pattern for the player | |
; It then puts each match into PlayerList | |
While Pos := RegExMatch( ReqObject.ResponseText, ".*?player\/(\w{13,16})+"">(.*?)<",_, !Pos?(1, (file_?(PlayerList:=""):"")):Pos+StrLen(_) ) | |
{ | |
PlayerList .= _2 "`n" | |
} | |
if ( file_ ) ; if a file is supplied in the function call, it will write to file too. | |
FileAppend % PlayerList, % file_ | |
} | |
return PlayerList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment