AutoHotkey Community

It is currently May 27th, 2012, 1:35 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: November 21st, 2009, 1:29 am 
Offline

Joined: September 19th, 2008, 9:07 pm
Posts: 15
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 4:33 am 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
something about a tutorial

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 4:59 am 
Offline

Joined: July 18th, 2006, 12:18 pm
Posts: 403
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? :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 6:47 am 
Offline

Joined: September 19th, 2008, 9:07 pm
Posts: 15
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 1:03 pm 
Offline

Joined: July 18th, 2006, 12:18 pm
Posts: 403
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 7:25 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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? :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:

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

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 8:50 pm 
Offline

Joined: September 19th, 2008, 9:07 pm
Posts: 15
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');


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 3:21 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
What does the page do when you execute that script? Does it load a new page? Open a pop-up window?

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 3:28 am 
Offline

Joined: July 18th, 2006, 12:18 pm
Posts: 403
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! :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 3:52 am 
Offline

Joined: September 19th, 2008, 9:07 pm
Posts: 15
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 3:54 am 
Offline

Joined: September 19th, 2008, 9:07 pm
Posts: 15
i3egohan,

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 4:06 am 
Offline

Joined: July 18th, 2006, 12:18 pm
Posts: 403
No problem... Just keep reading that manual.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], bobbysoon, iDrug, Tipsy3000, Yahoo [Bot] and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group