in reply to www::mechanize returning a page to a particular frame

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.

Replies are listed 'Best First'.
Re^2: www::mechanize returning a page to a particular frame
by nosbod (Scribe) on Jan 19, 2007 at 14:16 UTC
    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.