AutoHotkey Community

It is currently May 27th, 2012, 1:34 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: May 9th, 2009, 9:19 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
i have made changes to you code
Let me knwo how it works out for you
Code:
COM_CoInitialize()
SetTitleMatchMode,2
OnExit,ReleaseAll

MsgBox This script will move the cursor across the screen looking for two links. news.google.com and maps.google.com`nWhen it finds the link, it will click on it, display a traytip, fileappend links.txt then start over again until the program is paused or exited.`n`nPress`nF6 to Start`nF7 to ExitApp`nF8 to Pause`nF9 to Reload`nF10 to view Links.txt`n`nHow to Use-->`n1.  Open Google.com`n2.  Check how much memory IE is using, then press F6.`n3.  Watch the cursor find links.  Wait a minute or two, pause the script with F8 and check how much memory IE is using. For me the memory doubles in less then 5 mintues.`nThe longer I let the program run the more memory IE uses until IE becomes unresponsive due to low memory.`n`n`nNOTE: You may need to adjust StartingXpos, StartingYpos, EndingXpos and EndingYpos so the cursor can find the links.

EndingXpos = 400
EndingYpos = 150
StartingXpos = 10
StartingYpos = 120
MyGoogleUserID = UserID@gmail.com


F6::
Loop
 {
  WinWaitActive,Google
  MouseMove,%StartingXpos%,%StartingYpos%
  Startingxpos := Startingxpos+15
  ControlGetText,var,msctls_statusbar321, a

  if Startingxpos > %EndingXpos%
   {
    StartingXpos = 10
    StartingYpos := Startingypos+7
   }
  if Startingypos > %EndingYpos%
   {
    Send {F5}
    GoSub StatusBarDone
   }
 
  IfInString,Var,http://news.google.com ;example of link found by gettings the text from the statusbar
   {                                                       ;as the cursor hovers over the link
    TrayTip,Found Google News,%A_Space%,5,17
   sleep 2000
   click
   Gosub StatusBarDone
   }
 
  IfInString,Var,http://maps.google.com ;example of link found by gettings the text from the statusbar
   {                                                      ;as the cursor hovers over the link
   TrayTip,Found Google Maps,%A_Space%,5,17
   sleep 2000
   click
   Gosub StatusBarDone
   }
 }


F7::
ExitApp

F8::
Pause
Return

F9::
Reload

F10::
run notepad.exe Links.txt
Return

StatusBarDone:
StartingXpos = 10
StartingYpos = 120
TrayTip,Waiting for page to load,%a_space%,30,17
TrayTip, % IEReady(),%a_space%,5,17

WinGetText,text,A
IfInString,text,news.google.com                        ;StatusBarDone gets the window text
 FileAppend,Found news.google.com`n,Links.txt

IfInString,text,maps.google.com
 FileAppend,Found maps.google.com`n,Links.txt

Gosub GetHtmlSourceCode
IfInString,HtmlCode,%MyGoogleUserID%                   ;StatusBarDone gets the html source code
 FileAppend,I am signed in to Google`n`n,Links.txt
Else
 FileAppend, I am NOT signed in to Google`n`n,Links.txt
Return


IEReady(hIESvr = 0)
{
   If   !pweb:=iWeb2_GetIE(hIESvr)
      return false
   Loop,20
      If   COM_Invoke(pweb, "ReadyState") <> 4
         Break
      Else   Sleep 500
   Loop
   {
      If   COM_Invoke(pweb, "ReadyState") = 4
         Break
      Sleep 500
      Else
      {
         CountNumberOfSleeps++
         Sleep 500
         If CountNumberOfSleeps > 360 ;360 x 500 = 180 seconds
         {
            TrayTip,Taking to long to load webpage,Will abort waiting,5,17
            CountNumberOfSleeps = 0
            Break
         }
      }
   }
   COM_Release(pweb)
   Return   "DONE!"
}

GetHtmlSourceCode:
htmlcode:=pweb:=iWeb2_GetIE() ?  COM_Invoke(pweb, "document.documentElement.outerHTML") :
COM_Release(pweb)
return

ReleaseAll:
com_couninitialize()
exitapp



;: Title: iWebBrowser2 working with IE

;
; Function: iWeb2_GetIE
; Description: Gets the iWebBrowser2 interface from the passed parameter
; Syntax: pweb:=iWeb2_GetIE("google.com")
; Parameters: hIESvr - this can be anny of the following items
;                       IEFrame
;                       Internet Explorer_Server
;                       all or partial LocationURL
;                       all or partial LocationName
;                       blank in which case the last active IE window is selected
; Return Value: iWebBrowser2 interface
; Remarks:
; Related: Related, functions
; Example:
;
iWeb2_GetIE(IE="",Method="LocationName")
{
   
   IE:=(!IE && Method="HWND") ? WinExist("ahk_class IEFrame") : (!IE && Method="LocationName") ?  ActiveTitle() : (!IE && Method="LocationURL") ?  ActiveURL() ? !IE ? Exit : IE ; its blank use the active window
   
   psh   :=   COM_CreateObject("Shell.Application"),   psw   :=   COM_Invoke(psh,   "Windows"),   COM_Release(psh)
   Loop, %   COM_Invoke(psw,   "Count")
      ErrorLevel:=(pweb:=InStr(COM_Invoke(psw,"Item[" A_Index-1 "]." Method),IE) ? COM_Invoke(psw,"Item",A_Index-1) : 0) ? break : "iWeb2_GetIE(%IE%,%Method%) could not return a iWebBrowser2 interface"
   COM_Release(psw)
   Return   pweb
}
ActiveURL()
{
   ControlGetText, URL,Edit1,ahk_class    IEFrame
   Return URL
}


ActiveTitle()
{
   WinGetTitle,title,ahk_class    IEFrame
   StringSplit,t,title,- ; strip off the browser suffix
   t1=%t1% ;strip trailing and leading spaces
   Return   t1
}

_________________
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: May 10th, 2009, 12:14 am 
Offline

Joined: April 27th, 2008, 5:28 pm
Posts: 489
I get a error when I run the code you posted.

COM Error Notification
Function Name: "document"
ERROR: The COM Object may not be a valid Dispatch Object!
First ensure that COM Library has been initialized throught COM_init().

_________________
Check out my scripts.
(MyIpChanger) (XPSnap) (SavePictureAs)

All my scripts are tested on Windows 7, AutoHotkey_L 32 bit Ansi unless otherwise stated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 10th, 2009, 1:32 am 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
Doh :shock: My mistake ddint test this should fix it
Code:
IEReady(hIESvr = 0)
{
   If   !pweb:=iWeb2_GetIE(hIESvr)
      return false
   Loop,20
      If   COM_Invoke(pweb, "ReadyState") <> 4
         Break
      Else   Sleep 500
   Loop
   {
      If   COM_Invoke(pweb, "ReadyState") = 4
         Break
      ,Sleep 500
      Else
      {
         CountNumberOfSleeps++
         Sleep 500
         If CountNumberOfSleeps > 360 ;360 x 500 = 180 seconds
         {
            TrayTip,Taking to long to load webpage,Will abort waiting,5,17
            CountNumberOfSleeps = 0
            Break
         }
      }
   }
   COM_Release(pweb)
   Return   "DONE!"
}

GetHtmlSourceCode:
htmlcode:=(pweb:=iWeb2_GetIE()) ?  COM_Invoke(pweb, "document.documentElement.outerHTML") :
COM_Release(pweb)
return

_________________
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: May 10th, 2009, 6:20 am 
Offline

Joined: April 27th, 2008, 5:28 pm
Posts: 489
It is not the code, it is Internet explorer.

I manually clicked on google maps, google news, google maps, google news.

I did that for a few minutes and the memory usage was up to 202 mb very quickly.

I don't understand why IE is doing this. It does it on Vista and Win xp with IE7 and IE 8.

Must be something wrong with IE.

DataLife

_________________
Check out my scripts.
(MyIpChanger) (XPSnap) (SavePictureAs)

All my scripts are tested on Windows 7, AutoHotkey_L 32 bit Ansi unless otherwise stated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 10th, 2009, 7:53 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
I wouldn't be so quick to conclude IE is the (only) problem. Doesn't Google Maps use ActiveX, and therefore also have code running on your computer, using memory? Does it happen on other websites?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 10th, 2009, 3:41 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
I concurr entirely
I never bothered running the script so i didint check memory usage
I can tell you that the company i work for has me using ahk to automate 10's of thousands of page hits scrapes and clicks. and if everything is properly released then it never bloats memory.
Google fyi is notorious for using non standard client side code and in many cases not destroying objects within active x controls

This is almost certanly a problem with the page code not IE or COM
The only reason i altered your code for getting pdoc is because i am more familiar with the method io used not because it works less effectively
I could not and still do not see improperly handled objects in your latest copy of code

_________________
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: May 11th, 2009, 5:18 am 
Offline

Joined: April 27th, 2008, 5:28 pm
Posts: 489
I had not thought about googles code causing it. I checked other web pages and the memory is released properly.

thanks
DataLife

_________________
Check out my scripts.
(MyIpChanger) (XPSnap) (SavePictureAs)

All my scripts are tested on Windows 7, AutoHotkey_L 32 bit Ansi unless otherwise stated.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, chaosad 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