hudo has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'd like to fetch a http-site with a perl-script, fill in the form with the script, open the modifyed http-site with firefox/browser. Therefore I tested, fetching with WWW::Mechanize from Activestate Perl 5.10 and used Win32::Process to display the (original) URL. As far as I know Win32::Process needs a URL to display in a browser. Is it possible to display the modifyed page in firefox ?

Replies are listed 'Best First'.
Re: modifyed http page in browser
by Bloodnok (Vicar) on Apr 09, 2009 at 12:32 UTC
    I presume you mean you want to use Win32::Process to start a FF session in order to browse the URL.

    As far as your 2nd question is concerned, could you not use Win32::OLE to force a refresh of the browsed page in the browser (assuming FF supports OLE)...or, if not, I've seen recommendations regarding the use of elements of Win32::GuiTest to acheive similar goal(s) ?

    Update:

    Added Win32::GuiTest

    A user level that continues to overstate my experience :-))
Re: modifyed http page in browser
by dorward (Curate) on Apr 09, 2009 at 13:01 UTC
    I'd probably approach the problem with HTTP::Proxy which looks like it does what you want. Any browser should be able to connect to it.
Re: modifyed http page in browser
by Anonymous Monk on Apr 09, 2009 at 13:06 UTC
      From a quick look, HTML::Display looks like it might be a good fit for the original request. I also just noticed on CPAN that the email of the author is corion@blah which is naggingly familiar...

      --
      use JAPH;
      print JAPH::asString();

Re: modifyed http page in browser
by hudo (Novice) on Apr 10, 2009 at 09:50 UTC
    Sorry, cant get on. This is my actual code:
    #!/usr/bin/perl -w use WWW::Mechanize; use Win32::Process; use LWP; use strict; my $url="http://thewebside"; my $page; my $inhalt; my $firefoxpfad="C:\\firefox\\firefox.exe"; my $firefox="firefox"; ##### page holen ############################# $page = WWW::Mechanize->new( autocheck => 1 ); #$page = WWW::Mechanize->new(); $page->get($url); $page->success or die "Can't get the searched page"; #$page->form_name( "contactForm1" ); $page->form_number( 1 ); $page->field('contactFormId' => "1"); ### hidden field, is already s +et $page->field('name' => "myname"); $page->field('message' => "Hello"); ##### page speichern ######################## $inhalt = $page->content; ## normally I would like to open firefox with $inhalt which should ## contain already the filled fields ## but here I save it to disk #print $inhalt; open (ERGEBNISFILE, ">ergebnisfile.html") || die "Kann \"ergebnisfile\ +" nicht oeffnen $!"; printf ERGEBNISFILE "%s\n" ,"$inhalt"; close (ERGEBNISFILE); =BEGIN ##### open in browser ##################### Win32::Process::Create( my $ProcessObj, ### win xp "$firefoxpfad", "$firefox $url", 0, NORMAL_PRIORITY_CLASS, ".") || die ErrorRepor +t(); =END =cut
    Problem:
    1. $inhalt does not contain, the filled fields e.g. message with Hello . There is only 1 form on the side. Why are the fields not filled ?
    2. Like to open firefox with the filled form. 3. I looked at HTML::Display module, but the simple example
    display("<html><body><h1>Hello world!</h1></body></html>");
    opens only with IE, I'd like to use firefox instead. If I try to open the real webside it starts loading with IE but then breaks.

      You seem to have three problems that are not related:

      $inhalt does not contain, the filled fields e.g. message with Hello . There is only 1 form on the side. Why are the fields not filled ?

      This is because the content method is and stays the original content as returned from the webserver. You might or might not want HTML::FillInForm to populate the content with some more values.

      2. Like to open firefox with the filled form.
      3. I looked at HTML::Display module, but the simple example

      Like I wrote to somebody just yesterday in an email, that's likely just not possible under Windows unless you write some code that makes HTML::Display use temp files that have a .html extension.

      I'd like to use firefox instead. If I try to open the real webside it starts loading with IE but then breaks.

      That's a very common yet entirely unhelpful error diagnostic. Unless you're talking about porcelain or wood, you need to be more specific about what breaks and how. In the mail I sent yesterday to some person, I mentioned the location parameter which sets the base attribute of the HTML. Maybe the page tries to access some "local" resources like JavaScript scripts or images, which need the URL of the originating page. Which is what the location parameter should be set to.