 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Vega
Joined: 19 Sep 2008 Posts: 13
|
Posted: Sat Nov 21, 2009 12:29 am Post subject: Getting data from SharkScope.com (javascript, COM library) |
|
|
Hi guys,
I'm trying to write a script that uses sharkscope.com to get some data.
| Code: |
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 |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 3700 Location: Louisville KY USA
|
Posted: Sat Nov 21, 2009 3:33 am Post subject: |
|
|
something about a tutorial _________________
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed; |
|
| Back to top |
|
 |
i3egohan
Joined: 18 Jul 2006 Posts: 403
|
Posted: Sat Nov 21, 2009 3:59 am Post subject: |
|
|
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.
| Code: | 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?  |
|
| Back to top |
|
 |
Vega
Joined: 19 Sep 2008 Posts: 13
|
Posted: Sat Nov 21, 2009 5:47 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
i3egohan
Joined: 18 Jul 2006 Posts: 403
|
Posted: Sat Nov 21, 2009 12:03 pm Post subject: |
|
|
I cant follow or sniff the requests the javascript is making because i get the following message.
| Quote: | | You can only use that function if you are logged in |
Meaning i havent got a account on that site. |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
Posted: Sat Nov 21, 2009 6:25 pm Post subject: |
|
|
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):
| Code: | 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();
)
InputBox, username, Username, Please enter a username to search. ; saves username to var for use later
if (ErrorLevel || !username || RegExMatch(username,"^\s+$"))
return ; 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
Loop, Parse, jscall, `n, `r ; parses jscall list and sends each command
{
ControlSetText, Edit1, %A_LoopField% ; sets javascript in the address bar
ControlSend, Edit1, {ENTER} ; sends 'ENTER' to the address bar
}
WinWaitActive SharkScope
Sendinput %username%{Enter}
Sleep 500
ControlSetText, Edit1, javascript:addGraphWithRecentResults('%username%#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.
| Code: | run iexplore.exe http://www.sharkscope.com
Winwait SharkScope
IEReady() ; sleep 3000 |
| Vega wrote: | | ...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? 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:
| Code: | InputBox, username, Username, Please enter a username to search.
if (ErrorLevel || !username || RegExMatch(username,"^\s+$"))
return
js=javascript:ClearRecentGames('%username%#fulltilt&null', true,'50');
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,"javascript:showplayersearch();") ; 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,js) ; exceutes your last 50 games script for the appropriate user |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
Vega
Joined: 19 Sep 2008 Posts: 13
|
Posted: Sat Nov 21, 2009 7:50 pm Post subject: |
|
|
Thank you, this should help.
Any idea how to get into var what the javascript (below) returns without the ugly copying?
| Code: | | javascript:ClearRecentGames('%username%#fulltilt&null', true,'50'); |
|
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
|
| Back to top |
|
 |
i3egohan
Joined: 18 Jul 2006 Posts: 403
|
Posted: Sun Nov 22, 2009 2:28 am Post subject: |
|
|
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. [url]Then navigate to http://md5-hash-online.waraxe.us[/url] 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.
| Code: | ; SETUP
siteUsername = you@site.com ; 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!  |
|
| Back to top |
|
 |
Vega
Joined: 19 Sep 2008 Posts: 13
|
Posted: Sun Nov 22, 2009 2:52 am Post subject: |
|
|
| sinkfaze wrote: | | 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. |
|
| Back to top |
|
 |
Vega
Joined: 19 Sep 2008 Posts: 13
|
Posted: Sun Nov 22, 2009 2:54 am Post subject: |
|
|
i3egohan,
This is great! Thank you very much. It's a much better solution that I hoped for. |
|
| Back to top |
|
 |
i3egohan
Joined: 18 Jul 2006 Posts: 403
|
Posted: Sun Nov 22, 2009 3:06 am Post subject: |
|
|
| No problem... Just keep reading that manual. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|