personx1212 0 Newbie Poster

hi, i want to be able to intercept IE connections and get the URL before the contents are downloaded, either when clicking on a link or entering the address directly in the Addressbar, i found some examples on the web and made some changes but still some things are not clear.

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

>>> ie=win32com.client.DispatchWithEvents('InternetExplorer.Application',IE_Events)

i think through the above i can only get events from IE instances i launch my self:

>>> ie.Visible = True
>>> ie.Navigate('http://www.google.com')

-------------------------------------------

but how can i setup a listener/hook to get events from any IE instance, can you please give me some pointers on how a simple URL logger work?

Thank you.

Dani AI

Generated

: your current DispatchWithEvents approach only hooks the specific InternetExplorer.Application object you create. For catching navigations from already-running or user-launched IE windows there are three practical approaches.

First, a pure-Python route is to enumerate the Shell.Application Windows() collection, detect which items are Internet Explorer IWebBrowser2 objects, and attach an event sink (BeforeNavigate2) to each. Keep those sinks alive and either re-enumerate periodically or subscribe to ShellWindows registration events so new windows get hooked. Important notes: COM event sinks require a Windows message pump (for example pythoncom.PumpMessages) so callbacks run; your script must match IE bitness (32 vs 64 bit) and run at the same integrity level as the IE processes, otherwise attachment will fail.

Second, for a robust, always-loaded solution implement a Browser Helper Object (BHO). A BHO is an in-process COM DLL that IE loads for every window and can sink DWebBrowserEvents2 before download begins. That is the production choice for full coverage, but it requires native COM code, registration under the BHO registry key, and attention to IE security/protected-mode caveats.

Third, if the goal is just URL logging across browsers, run a local HTTP proxy and configure IE to use it. This captures all requests without in-process hooks; HTTPS will be encrypted unless you perform a TLS interception and install a trusted cert.

Troubleshooting tips: verify you are attaching to IWebBrowser2 (not the document), ensure a message loop is running, confirm bitness and integrity-level parity, and test with freshly-launched IE instances while iterating on the attachment logic.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.