Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Getting data from SharkScope.com (javascript, COM library)


  • Please log in to reply
11 replies to this topic
Vega
  • Members
  • 17 posts
  • Last active: Feb 26 2015 02:32 PM
  • Joined: 19 Sep 2008
Hi guys,

I'm trying to write a script that uses sharkscope.com to get some data.

run iexplore.exe http://www.sharkscope.com
Winwait SharkScope
sleep 3000
Sendinput ^o
WinWaitActive Open
Sendinput javascript:showplayersearch();
Sendinput {Enter}
WinwaitActive SharkScope
Sendinput ^o
WinWaitActive Open
Sendinput javascript:document.findplayerform.FindString.focus();
Sendinput {Enter}
WinwaitActive SharkScope
Sendinput belle33{Enter} ; or any nick
Sleep 500
Sendinput ^o
WinWaitActive Open
Sendinput {Raw}javascript:addGraphWithRecentResults('belle33#fulltilt&null');
Sendinput {Enter}
sleep 2000
loop 
{
	Sendinput ^a
	sleep 200
	Sendinput ^c
	winwait 1
	If clipboard <> 
		break
}
results := clipboard

It's pretty basic, but it works. (somewhat reliably)
I know I could do this much better with COM library, but that is somehting that is way beyond me. I know, I tried.

Could someone help me with this?

The main thing I'd need is a way to get into var the recent results (the list that javascript:addGraphWithRecentResults('belle33#fulltilt&null') gets) without having to copy the whole page and get the data from the clipboard. Is there a javascript command for this?

Also, can this whole thing (getting the data I need) be done in the background, without opening an IE window?

I thank you for any help.

Vega

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
something about a tutorial
Never lose.
WIN or LEARN.

i3egohan
  • Members
  • 403 posts
  • Last active: Feb 15 2012 12:07 PM
  • Joined: 18 Jul 2006
Thats a very ugly way to achive this.

I followed/sniffed the javascript.. To see what pages it was requesting. I managed to write this code which doesnt open any windows or anything.. It does everything in the background.

You may need to organise the results depending on what you want to do with them.

username = belle33 ; username to get results

URLDownloadToFile, http://www.sharkscope.com/SharkScope/FindRecentGames?searchstring=%username%&Network=fulltilt&Username=sswebsite&Password=&localFilter=null, %A_Temp%/ssresults.txt ; Download html
FileRead, html, %A_Temp%/ssresults.txt ; Read the html in a variable
FileDelete, %A_Temp%/ssresults.txt ; Delete the downloaded html, We already have it in memory

Loop, Parse, html, `; ; Read each result
    MsgBox % A_LoopField ; Display results

Alot cleaner then your method. Dont ya think? :D

Vega
  • Members
  • 17 posts
  • Last active: Feb 26 2015 02:32 PM
  • Joined: 19 Sep 2008
This is a very interesting and elegant solution. Thank you. Certanly more so than mine. And you didn't spend 2 days doing it. :)

But I can't follow the javascript requests, so could you also look into what is required to request not the last 8 but the last 50 games?
I absolutely need this, but wanted to keep the posted code simple and didn't post the whole thing.
There is a part where if the user played more than 8 games since last checked it requests 50 games.
The javascript for this:
javascript:ClearRecentGames('belle33#fulltilt&null', true,'50');


tank, yes I know about the tutorials. I tried to read them. It's like trying to teach someone from the Dark Ages about the internet. You can make a tutorial about what it is and how to use it, but he'll never understand it without understanding a million other thing that lead to this pont. Like electricity :) That's how much help those tutorials are for someone like me, who is not so interested in the inner workings of various software technologies.

i3egohan
  • Members
  • 403 posts
  • Last active: Feb 15 2012 12:07 PM
  • Joined: 18 Jul 2006
I cant follow or sniff the requests the javascript is making because i get the following message.

You can only use that function if you are logged in


Meaning i havent got a account on that site.

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
Well if you're looking to make your existing code a little more reliable, you could try using using ControlSetText/ControlSend instead of Send (untested obviously):

SetKeyDelay, 10, 10 ; may make ControlSend work more reliably
SetControlDelay, -1 ; no delay in working with controls
jscall= ; variable to save the back-to-back javascript calls to
(
javascript:showplayersearch();
javascript:document.findplayerform.FindString.focus();
)

[color=red]InputBox, username, Username, Please enter a username to search. ; saves username to var for use later
if (ErrorLevel || !username || RegExMatch(username,"^\s+$"))
  return[/color] ; if the user presses cancel, if username is blank or contains nothing but whitespace, ends script
run iexplore.exe http://www.sharkscope.com
Winwait SharkScope
sleep 3000
[color=red]Loop, Parse, jscall, `n, `r[/color] ; parses jscall list and sends each command
{
[color=red]  ControlSetText, Edit1, %A_LoopField%[/color] ; sets javascript in the address bar
[color=red]  ControlSend, Edit1, {ENTER}[/color] ; sends 'ENTER' to the address bar
}
WinWaitActive SharkScope
Sendinput [color=red]%username%[/color]{Enter}
Sleep 500
ControlSetText, Edit1, javascript:addGraphWithRecentResults('[color=red]%username%[/color]#fulltilt&null');
ControlSend, Edit1, {Enter}
sleep 2000
Current=%Clipboard%
Clipboard=
ClipWait
Loop {
  Sendinput ^a
  sleep 200
  Sendinput ^c
  ClipWait, 0.5
  if Clipboard ; essentially the same as ' if Clipboard <> "" '
    break
}
results := clipboard
Clipboard=%Current%
return

It appears you also have Sleep periods in your script as if to wait for a page to load. You can use StatusBarWait to get a better idea of when the page is loaded or Sean's IEReady() function for a more reliable method.

run iexplore.exe http://www.sharkscope.com
Winwait SharkScope
[color=red]IEReady()[/color] ; sleep 3000

...someone like me, who is not so interested in the inner workings of various software technologies.


Say what? You came here manipulating a page with javascript calls and you're not interested in the inner workings? :lol: Maybe an updated tutorial is in order at some point but the information that's out there is pretty plentiful and using tank's iWeb functions a task like yours could be much easier. This code is possibly a rough equivalent of what you're doing:

InputBox, username, Username, Please enter a username to search.
if (ErrorLevel || !username || RegExMatch(username,"^\s+$"))
  return
[color=red]js=javascript:ClearRecentGames('%username%#fulltilt&null', true,'50');[/color] 
run iexplore.exe http://www.sharkscope.com
Winwait SharkScope
pwb:=iWeb_getWin("SharkScope") ; obtains a 'pointer' reference to the page
iWeb_Complete(pwb) ; waits for the page to complete loading
iWeb_execScript(pwb,"[color=red]javascript:showplayersearch();[/color]") ; executes the script
;iWeb_Complete(pwb) ; uncomment if waiting for page load
iWeb_setDomObj(pwb,"FindString",username) ; puts the username in the box
Send {ENTER} ; or iWeb_clickDomObj(pwb,"<< button name >>")
iWeb_Complete(pwb)
iWeb_execScript(pwb,[color=red]js[/color]) ; exceutes your last 50 games script for the appropriate user


Vega
  • Members
  • 17 posts
  • Last active: Feb 26 2015 02:32 PM
  • Joined: 19 Sep 2008
Thank you, this should help.
Any idea how to get into var what the javascript (below) returns without the ugly copying?

javascript:ClearRecentGames('%username%#fulltilt&null', true,'50');


sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
What does the page do when you execute that script? Does it load a new page? Open a pop-up window?

i3egohan
  • Members
  • 403 posts
  • Last active: Feb 15 2012 12:07 PM
  • Joined: 18 Jul 2006
Ok i have to explain a little about this part.

Since returning 10 or more results from sharkscope requires you to be logged in, You have to set username and password.

However we have to pass the encrypted version of your password. sharkscope uses MD5.

So before using the script.. set the variable 'siteUsername' to your username on sharkscope. Then navigate to <!-- m -->http://md5-hash-onli...xe.us<!-- m --> In the big edit box type your password..And click "Calculate MD5 hash" this will return a 32 character string.. This is the value you must put in 'sitePassword'

Once you have done the above you can alter how many results/recent games you return by editing the variable 'amountResults' its currenly set to 50. this will return 50 recent games info.

Ive tested the code with the user/pass you sent me and it works fine. Ive also pmed you a copy where i already included your user/pass.

; SETUP
siteUsername  = [email protected] ; replace this with your sharkscope username 
sitePassword  = 5f4dcc3b5aa765d61d8327deb882cf99 ; replace this with your sharkscope password. MUST BE IN MD5 format. 
userSearch    = belle33 ; username to get results for
amountResults = 50 ; Amount of recent games to retrive. This returns 50

URLDownloadToFile, http://www.sharkscope.com/SharkScope/FindRecentGames?searchstring=%userSearch%&Network=fulltilt&Username=%siteUsername%&Password=%sitePassword%&GeneralSearchType=SNGO&Filter= SNG Only&localFilter= SNG Only&ShowMoreGames=true&MoreGamesCount=%amountResults%, %A_Temp%/ssresults.txt ; Download html
FileRead, html, %A_Temp%/ssresults.txt ; Read the html in a variable
FileDelete, %A_Temp%/ssresults.txt ; Delete the downloaded html, We already have it in memory

Loop, Parse, html, `; ; Read each result
    MsgBox % A_LoopField ; Display results
    
; In the loop above you can CLEAN the results.. using StringReplace and/or RegexReplace etc.

Good luck! :D

Vega
  • Members
  • 17 posts
  • Last active: Feb 26 2015 02:32 PM
  • Joined: 19 Sep 2008

What does the page do when you execute that script? Does it load a new page? Open a pop-up window?


It places a 50 games list in the same page. It can't be executed without
running javascript:addGraphWithRecentResults('%username%#fulltilt&null');
first, which shows three graphs and a list of 8 games.
This last javascript can be used without logging in (5 free search / day), if you want to see.

Vega
  • Members
  • 17 posts
  • Last active: Feb 26 2015 02:32 PM
  • Joined: 19 Sep 2008
i3egohan,

This is great! Thank you very much. It's a much better solution that I hoped for.

i3egohan
  • Members
  • 403 posts
  • Last active: Feb 15 2012 12:07 PM
  • Joined: 18 Jul 2006
No problem... Just keep reading that manual.