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

I'm scraping a site that has
<form action="#" name="someform">
and an image with a javascript onclick event that set's the action depending on what graphic was clicked. I did't see a way to set the action attribute using WWW::Mechanize. I'm using mehcanize because the site stores cookies and sessions and requires multi-page navigation - so I thought Mechanize was the way to go, but I'm very new to Perl. Suggestions? The code I've been working on (don't laugh too hard) is here if it helps.

Replies are listed 'Best First'.
Re: How to set Form action attribute using WWW:Mechanize
by davidrw (Prior) on Jun 26, 2005 at 03:16 UTC
    WWW::Mechanize will give you HTML::Form objects, so you can manually set the action attribute like this:
    my $form = $mech->current_form(); $form->action($new_action);
      Thanks SO much - duh - I guess I should have gotten that :) Stupid C# coders - Perl isn't for kids. :) On the off chance someone is as novice as me, on top of what the person suggested above... this is what worked:
      #where $agent = WWW::Mechanize->new(); my $form = $agent->form_name('someformname'); $form->action('http://www.something.com/someform'); $agent->submit(); #doing a $form->submit(); - gives you a funny "unblessed #error" which took me a while to grok
Re: How to set Form action attribute using WWW:Mechanize
by dorko (Prior) on Jun 26, 2005 at 02:35 UTC
    Welcome to the Monastery, wiseleyb.

    As you've figured out, WWW::Mechanize doesn't do javascript.

    You might try something like Live HTTP Headers for Mozilla / Firefox to see exactly what the browser is sending and then hard code into your script what you need to send. It's not nice and programmatic, but you should be able to get it to work.

    Also, rather than linking to code externally, others will tell you it's a bit of a custom here to show the smallest snippet of your code that illustrates your problem.

    Cheers,

    Brent

    -- Yeah, I'm a Delt.