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

I'm using mech as part of a scrape of an HTML page that is driven by a hidden form that looks like this:

<form name="content" method="post" id="Form2">
<input type="hidden" size="-1" name="cid" id="Hidden5">
<input type="hidden" size="-1" name="cntid" id="Hidden6">
<input type="hidden" size="-1" name="attid" id="Hidden7">

Note it is a POST. The form content is set by in a link that looks like this
<a href="javascript:popContent('detail',1234,0,0);">Something</a>

The javascript itself looks like this
function popContent(action,cid,cntid,attid) { if (action == "detail") { document.content.cid.value = cid; document.content.action = "detail.asp"; document.content.submit(); } else { document.content.cid.value = cid; document.content.cntid.value = cntid; document.content.attid.value = attid; document.content.action = "preview.aspx"; document.content.submit(); } }
When the user clicks on the link what happens at the end of the day is that the POST equivalent of this GET happens

http://..../detail.asp?cid=1234&cntid=&attid=

Sooooo my question is how do I deal with detail.asp from within mech? I can set cid, etc. so all that is OK. But how do I deal with document.content.action = "detail.asp"?

My second question (I hope I'm allowed more than one) is how can I make a copy of the current mech to use so I don't step on the 1st mech's environment since I'll need it later. Like having two browsers going.
Thanks

Replies are listed 'Best First'.
Re: WWW::Mechanize questions
by perrin (Chancellor) on Oct 28, 2005 at 00:31 UTC
    I think you just want this:
    $mech->form_name('content')->action('preview.aspx');
    Note that you may have to turn off the readonly() attribute of those hidden inputs before Mech will let you change them.

    To make a full copy of a Mech object, try Storable's dclone() method.

      A bit of reading (RTFM puff) reveals from CPAN
      WWW::Mechanize is a proper subclass of LWP::UserAgent and you can also use any of LWP::UserAgent's methods.
      And then for LWP::Agend
      $ua->clone; ... Returns a copy of the LWP::UserAgent object
      And of course
      $mech->request( $request [, $arg , $size])