Can CleintForm work with webbrowser?
Chris Rebert
clp2 at rebertia.com
Mon Mar 2 00:49:51 EST 2009
On Sun, Mar 1, 2009 at 9:36 PM, Muddy Coder <cosmo_general at yahoo.com> wrote:
> Hi Folks,
>
> ClientForm is cool at grabbing and parsing stuff from server, I like
> it. After the stuff parsed, and even filled values for the Controls, I
> popped up an idea of displaying what I had done with webbrowser. Look
> at the code:
>
> import ClientForm
> import urllib2
> import webbrowser
>
> request = urllib2.Request(url)
> response = urllib2.urlopen(request)
> forms = ClientForm.ParseResponse(response, backwards_compat=False)
> ...parsing and filling forms
>
> # now I want to display the forms I modified, with webbrowser
> webbrowser.open_new_tab (???)
>
> ??? is supposed to be a url. But this moment I want to display the
> form I filled. Obviously webbrowser takes url as argument rather than
> a form. Is there other options to do this? Somebody can help? Thanks!
You could run a local HTTP server in another Python process/thread
using SimpleHTTPServer
(http://docs.python.org/library/simplehttpserver.html) and have it
serve the modified webpage you produce. Then you could call webbrowser
with a localhost address corresponding to the HTTP server you're
running.
Cheers,
Chris
--
Shameless self-promotion:
http://blog.rebertia.com
More information about the Python-list
mailing list