How to receive events (eg. user mouse clicks) from IE

Roger Upole rupole at hotmail.com
Thu May 19 03:10:22 EDT 2005


The two you'll need to run makepy for are Microsoft Internet Controls and
Microsoft HTML object Library.  If you run them manually, you should be
able to look at the generated code to get the guids.
Here's a minimal example:

import win32com.client

ie_mod=win32com.client.gencache.EnsureModule('{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}',0, 
1, 1)
class IE_Events(ie_mod.DWebBrowserEvents2):
    def OnNavigateComplete2(self, pDisp, URL):
        print 'OnNavigateComplete2:', URL

ie=win32com.client.DispatchWithEvents('InternetExplorer.Application',IE_Events)
ie.Visible=1
ie.Navigate('http://www.google.com')

   hth
      Roger


<cal_2pac at yahoo.com> wrote in message 
news:1116476411.853695.235670 at g14g2000cwa.googlegroups.com...
>I am trying to trap events from internet explorer eg. when user clicks
> on an html link - I need to get notified for that event.
>
> After looking through the newgroups / internet and reading through
> various sections in programming python on win32 - I understand that
> this can be done using DispatchWithEvents.
> I have also referred to discussions on comp.lang.python
> http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/a3c502d06412a5f8/0ee3083e71316da7?q=dispatchwithevents&rnum=43#0ee3083e71316da7
>
> and
>
> http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/1da0668794851296/5bcec1fda216c598?q=dispatchwithevents&rnum=19#5bcec1fda216c598
>
> So far - none of the newgroups postings report that IE events were
> trapped successfully (at least I could not find any). However, there is
> enough evidence that it can be done.
> My problems at the moment:
> a) The examples use early binding. However, I cannot get Python makepy
> to generate the code to force makepy process at run time - since COM
> makepy utility that I invoke from python win 32 does not have any entry
> for internet explorer.
> I tried to find the CLSID for IE 3050F613-98B5-11CF-BB82-00AA00BDCE0B
> but I get an exception
> b) Also one of the examples suggest that following code should work
>
>> mod = EnsureModule(...)
>
>> class MyEvents(mod.IDocumentEvents):
>>    # your methods here....
>
>> handler = MyEvents(ie.document)
>
>> # handler should start recieving events.
>
> however, what CLSID is to be used in EnsureModule... . I tried with a
> few but I always get the error 'NoneType' object has no attribute
> 'IDocumentEvents'
>
>
> An example that 'works' will be very useful
> 



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----



More information about the Python-list mailing list