views:

111

answers:

2

How can I do this with Firefox or Google Chrome?

ie = win32com.client.Dispatch('InternetExplorer.Application')
ie.visible = 1
ie.navigate('http://google.com')

Is there a way to do it?

ps: I need to use the ReadyState with it... for example while (ie.ReadyState != 4):, or in other words, I need some command that wait until the page loads completely until do the next command, that's why I need the dispatch, that currently work very good with IE

+3  A: 

Firefox does not expose a COM object; this is not possible. (AFAIK)

You can use the webbrowser module to open a URL in the user's default browser.

SLaks
+1  A: 

Have a look at the webbrowser module in the Python standard library.

David Zaslavsky
webbrowser module can't give me the status ready of the dispatch... so I can use some ifs with it.... for example: while (ie.ReadyState != 4):
Shady
Do you really need that? If so, I guess you could try something with the `subprocess` module instead of `webbrowser`... but in that case, update your question to better specify your requirements.
David Zaslavsky
subprocess can give me something like the ReadyState? For example, can it wait until the page load completely to run the next command? That's what I want actually
Shady
`subprocess` would at least tell you whether the process launched properly, and would give you access to its standard output and error streams. It's possible that if Firefox produces output to indicate when it loads a page, you could parse the text on those streams to tell when the page is loaded. Otherwise, you'd have to write some sort of interface between Python and the native code in Firefox.
David Zaslavsky