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

Hi
I'm trying to return a page using www::mechanize. I'd like to specify the frame that the data is returned within. Is this possible?
$mech->get('https://somesite.com/view'); $mech->submit_form( fields => { idtype => "swiss", id => "id1", } );
thanks

Replies are listed 'Best First'.
Re: www::mechanize returning a page to a particular frame
by ferreira (Chaplain) on Jan 19, 2007 at 13:10 UTC

    Like adrianh said at Re: www::mechanize returning a page to a particular frame, WWW::Mechanize must be taught to navigate to the frame you want. That may be accomplished by using the method follow_link with some appropriate parameters. Maybe it also can be done by hardcoding the URL to the frame as referenced in the parent page HTML. Just take a look at the HTML page returned by 'https://somesite.com/view' and realize where is the link to your frame.

    A web browser does just that, downloading all the child files it needs to render the HTML document. While coding your navigation in a (Perl) program, you may be much more precise, getting only what you really need for the task at hand.

      ok, thanks. I was wondering whether it could be done directly without using  follow_link.
      Obviously not, nevermind.
      Thanks again
        You could write a plugin for WWW::Mechanize::Pluggable to handle this; you'd of course need to specify the frame you wanted to navigate into, but it's definitely possible. You could save the name of the frame in a get() prehook, do the get, and then follow_link() in a get() posthook to fetch the frame contents, returning that as the content. Since the follow_link happens in the posthook, your mainline code does something like
        $mech->get($the_frame_link, frame=>$subframe_name);
        and all the work happens under the covers. If you're going to need to do complex nested-frame navigation, you'd need a more refined interface to describe the frame nesting, but this'd do for what you've described. There are a number of plugins available on CPAN (in the Mech::Plugin namespace) as study aids in figuring out how to do this.

        Disclaimer: I wrote Mech::Pluggable, but it just makes extending Mech a little bit in any particular direction a lot easier to do.

Re: www::mechanize returning a page to a particular frame
by adrianh (Chancellor) on Jan 19, 2007 at 12:36 UTC
    I'm trying to return a page using www::mechanize. I'd like to specify the frame that the data is returned within. Is this possible?

    No. Frames are a client side concept - not a server side one. The server dosn't know about frames :-)