[python-win32] Internet Explorer constants

Mike Driscoll mdriscoll at co.marshall.ia.us
Fri Sep 5 22:38:35 CEST 2008


Hi Gabriel,
> <div class="moz-text-flowed" style="font-family: -moz-fixed">En Fri, 
> 05 Sep 2008 05:23:01 -0300, Tim Golden <mail at timgolden.me.uk> escribió:
>
>> Gabriel Genellina wrote:
>>> Hello
>>>  I want to control Internet Explorer. This is what I have so far:
>>>  import win32com.client
>>> from win32com.client.gencache import EnsureDispatch
>>> url = "..."
>>> IE = EnsureDispatch("InternetExplorer.Application")
>>> IE.Navigate(url)
>>> IE.Visible = 1
>>>  It works fine and shows the requested page. Now I want to use the 
>>> "Save As" command. Looks like I should call the
>>> IWebBrowser2.ExecWB method, passing IDM_SAVEAS as the command and 
>>> MSOCMDEXECOPT_DONTPROMPTUSER in the options. But I don't know how to 
>>> obtain the value for such constants... I could dig into the C header 
>>> files looking for them, but is there some other way?
>>>  The ExecWB method is documented here 
>>> http://msdn.microsoft.com/en-us/library/aa752117(VS.85).aspx
>>
>> The usual way to get at constants after a Dispatch
>> is via the win32com.client.constants object. In this
>> case, the constant you want is OLECMDID_SAVEAS which...
>>
>> <code>
>> import win32com.client
>>
>> IE = "InternetExplorer.Application"
>> ie = win32com.client.gencache.EnsureDispatch (IE)
>>
>> print win32com.client.constants.OLECMDID_SAVEAS </code>
>
> Ok, thanks! Looks like these are the names to use instead:
>
> IE.ExecWB(
>   constants.OLECMDID_SAVEAS,
>   constants.OLECMDEXECOPT_DONTPROMPTUSER,
>   filename,
>   None)
>
> Altough the ...DONTPROMPTUSER option doesn't work - the Save As dialog 
> always appears. Some kind of permission or safety measure, I presume.
>
> My original intent was to save the file using the .mht format, but 
> that format is not listed on the Save As dialog. I'll investigate 
> using IMessage.CreateMHTMLBody but that's a different topic.
>

You could also look at PAMIE: http://pamie.sourceforge.net/  or 
Mechanize: http://pypi.python.org/pypi/mechanize/0.1.7b

I don't think either uses the PyWin32 library, but I hear that they're 
both pretty good.

-------------------
Mike Driscoll

Blog:   http://blog.pythonlibrary.org
Python Extension Building Network:     http://www.pythonlibrary.org




More information about the python-win32 mailing list