AutoHotkey Community

It is currently May 27th, 2012, 2:05 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: January 31st, 2010, 2:57 pm 
Offline

Joined: August 20th, 2007, 6:57 pm
Posts: 185
so I been the tutorials and have a rough understanding of com and ahk Im trying to click the free user link in this website
http://uploading.com/files/get/1JM4429T/

my code works and will click everything but the free users link and i just don't know what im doing wrong or maybe its the site.
Code:
;iWeb_Init()
;upload:=iWeb_Model()
;iWeb_nav(upload,"http://uploading.com/files/get/1JM4429T/")

COM_Init()
pwb := COM_CreateObject("InternetExplorer.Application")
COM_Invoke(pwb , "Visible=", "True") ;"False" ;"True" ; comment this out to make invisible

url:="http://uploading.com/files/get/1JM4429T/"
COM_Invoke(pwb, "Navigate", url)
loop
If (rdy:=COM_Invoke(pwb,"readyState") = 4)
break

IID_IHTMLWindow2   :=   "{332C4427-26CB-11D0-B483-00C04FD90119}"
pwin:=COM_QueryService(pwb,   IID_IHTMLWindow2,   IID_IHTMLWindow2)
pdoc:=COM_Invoke(pwin, "Document")
links:=COM_Invoke(pdoc, "links")
link:=COM_Invoke(links, "Item",16) ;I changed the item number 1-15 and
;here are the results
;0-bannner
;1-nothing
;2-nothing
;3-home
;4-premuim membership
;5-sign up
;6-for partners
;7-faq
;8-top 100
;9-support ;
;10-premuim members
;11-TOS ;
;12-privacy
;13-dmcz
;14-file checker
;15-none
COM_Invoke(link, "click")
 sleep 1000
loop
If (rdy:=COM_Invoke(pwb,"readyState") = 4)
break

so far its goes to the site waits for it to load and then clicks whatever else i don't want it to. I tried using IE elements spy with no real help. in the code is listed the different item numbers I called for the link (don't think thats the correct termonolgy)

ps thank you TANK for your tut on COM
any suggestion im all open


Last edited by Mkbailey755 on February 1st, 2010, 11:13 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 31st, 2010, 3:50 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
The button you're trying to click isn't a link (or isn't classified as a link), so it isn't in the links collection. Try using the ahk web recorder (from this thread), once the recorder is open hold down the control button and hover the mouse over the button you're trying to click. You'll see that the tag type is 'button', so it would be in the button collection. You access the button collection slightly differently then you do the links collection:

Code:
COM_Invoke(pWin,"document.links.length") ; retrieves the number of link items
COM_Invoke(pWin,"document.all.tags[button].length") ; retrieves the number of button items


In the web recorder you'll also see in the Value/InnerText box that it says 'Free Download', so now we know the tag type of the button and the specific text of the button, so we can create a loop that will check all of the button items for one with the innerText 'Free Download':

Code:
Loop % COM_Invoke(pWin,"document.all.tags[button].length") { ; loop will only run for the amount of button items on the page
  if InStr(COM_Invoke(pWin,"document.tags[button].item[" A_Index-1 "].innerText"),"Free Download")
  {
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].click")
    break ; stop searching
  }
}


But that's not the end of it. If you check the OuterHTML box for the button you'll also notice that it contains a statement to the effect of 'onclick=....'; 'onclick' is a JavaScript event that is supposed to fire when the button is clicked, but our method may bypass that event and prevent the click from working properly. Luckily we can make that event occur manually:

Code:
Loop % COM_Invoke(pWin,"document.all.tags[button].length") {
  if InStr(COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].innerText"),"Free Download")
  {
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].click")
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].fireEvent","onclick")
    break
  }
}


So with a touch of code tidying:

Code:
url:="http://uploading.com/files/get/1JM4429T/"
IID_IHTMLWindow2:="{332C4427-26CB-11D0-B483-00C04FD90119}"

COM_Init()
pwb:=COM_CreateObject("InternetExplorer.Application")
COM_Invoke(pwb , "Visible=", "True")
COM_Invoke(pwb, "Navigate", url)
loop
  if COM_Invoke(pwb,"readyState") = 4
    break
pWin:=COM_QueryService(pwb,IID_IHTMLWindow2,   IID_IHTMLWindow2)
Loop % COM_Invoke(pWin,"document.all.tags[button].length") {
  if InStr(COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].innerText"),"Free Download")
  {
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].click")
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].fireEvent","onclick")
    break
  }
}
Sleep 1000
Loop
  if COM_Invoke(pwb,"readyState") = 4
    break


I believe that should work to click the 'Free Download' link.

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2010, 4:00 pm 
Offline

Joined: August 20th, 2007, 6:57 pm
Posts: 185
Thanks sink! works great and gives me the what i need on the next part of the code. :D
I understand Com ALOT better than I did 12hours ago. Thanks to the support of this forum Thanks again


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2010, 5:50 pm 
Offline

Joined: August 20th, 2007, 6:57 pm
Posts: 185
This winy post as been removed


Last edited by Mkbailey755 on February 1st, 2010, 9:02 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2010, 8:59 am 
Offline

Joined: August 20th, 2007, 6:57 pm
Posts: 185
Excuse the post above I was very tired and after much needed sleep Iam back at it.


Code:
url:="http://uploading.com/files/get/1JM4429T/"
IID_IHTMLWindow2:="{332C4427-26CB-11D0-B483-00C04FD90119}"

COM_Init()
pwb:=COM_CreateObject("InternetExplorer.Application")
COM_Invoke(pwb , "Visible=", "True")
COM_Invoke(pwb, "Navigate", url)
loop
  if COM_Invoke(pwb,"readyState") = 4
    break
pWin:=COM_QueryService(pwb,IID_IHTMLWindow2,   IID_IHTMLWindow2)
Loop % COM_Invoke(pWin,"document.all.tags[button].length") {
  if InStr(COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].innerText"),"Free Download")
  {
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].click")
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].fireEvent","onclick")
    break
  }
}
Sleep 1000
Loop
  if COM_Invoke(pwb,"readyState") = 4
    break

sleep, 85000 ;to cover the 60sec timer


pWin:=COM_QueryService(pwb,IID_IHTMLWindow2,   IID_IHTMLWindow2)
Loop % COM_Invoke(pWin,"document.all.tags[button].length") {
  if InStr(COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].innerText"),"Free Download")
  {
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].click")
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].fireEvent","onclick")
    break
  }
}

HAHA I repeated the code above to click the next link and ir works great for the first test now I get an error
Quote:
" function name: "readystate"
Error: the interface is Unknown
(0x800706b6)
Will Continue

Yes NO

hmm just my luck. I redownloaded my COM file thinking it got fubared any ideas?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2010, 11:09 am 
Offline

Joined: August 20th, 2007, 6:57 pm
Posts: 185
OK so I solved the error message problem it seems to not function when the website is Trusted not sure why maybe someone can chime in for some additional help.
so I finished the code yeah :D
Code:
url:="http://uploading.com/files/get/1JM4429T/"
IID_IHTMLWindow2:="{332C4427-26CB-11D0-B483-00C04FD90119}"

COM_Init()
pwb:=COM_CreateObject("InternetExplorer.Application")
COM_Invoke(pwb , "Visible=", "False")
COM_Invoke(pwb, "Navigate", url)
loop
  if COM_Invoke(pwb,"readyState") = 4
    break
pWin:=COM_QueryService(pwb,IID_IHTMLWindow2,   IID_IHTMLWindow2)
Loop % COM_Invoke(pWin,"document.all.tags[button].length") {
  if InStr(COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].innerText"),"Free Download")
  {
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].click")
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].fireEvent","onclick")
    break
  }
}
Sleep 1000
Loop
  if COM_Invoke(pwb,"readyState") = 4
    break

sleep, 85000


pWin:=COM_QueryService(pwb,IID_IHTMLWindow2,   IID_IHTMLWindow2)
Loop % COM_Invoke(pWin,"document.all.tags[button].length") {
  if InStr(COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].innerText"),"Free Download")
  {
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].click")
    COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].fireEvent","onclick")
    break
  }
}
sleep,5000
send {alt} o

Thanks for all the Help.
Maybe someone can find out why it won't work for trusted sites IDK
Net step is to Add a file Read line so I can save web links in a file and download them later. there was probably a much easier way to do this but I like making my own programs


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: engunneer, nimda, sjc1000 and 15 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