By MicrobicTiger


2014-03-26 02:11:09 8 Comments

I am trying to gather data from a website. Some anti-patterns make looking finding the right form objects difficult but I have this solved. I am using a post method to get around some javascript acting as a wrapper to submit the form. My problem seems to be in getting the results from the mechanize->post method.

Here's a shortened version of my code.

use strict;
use warnings;
use HTML::Tree;
use LWP::Simple;
use WWW::Mechanize;
use HTTP::Request::Common;
use Data::Dumper;
$| = 1;

my $site_url = "http://someURL"; 
my $mech = WWW::Mechanize->new( autocheck => 1 );
foreach my $number (@numbers) 
{
    my $content = get($site_url);
       $mech->get ($site_url);

    my $tree = HTML::Tree->new();

    $tree->parse($content);

    my ($title) = $tree->look_down( '_tag' , 'a' );
    my $atag = "";
    my $atag1 = "";
    foreach $atag ( $tree->look_down( _tag => q{a}, 'class' => 'button', 'title' => 'SEARCH'     )  ) 
    {
        print "Tag is ", $atag->attr('id'), "\n";
        $atag1 = Dumper $atag->attr('id');
    }

# Enter permit number in "Number" search field
    my @forms = $mech->forms;
    my @fields = ();
    foreach my $form (@forms)
    {
        @fields = $form->param;
    }
    my ($name, $fnumber) = $fields[2];
    print "field name and number is $name\n";
    $mech->field( $name, $number, $fnumber );
    print "field $name populated with search data $number\n" if $mech->success();

    $mech->post($site_url , 
    [
       '$atag1' => $number,
       'internal.wdk.wdkCommand' => $atag1,
    ]) ;

print $mech->content; # I think this is where the problem is.

}

The data I get from my final print statement is the data from teh original URL not the page the POST command should take me to. What have I done wrong?

Many Thanks

Update

I don't have Firefox installed so I'm avoiding WWW::Mechanize::Firefox intentionally.

1 comments

@MicrobicTiger 2014-03-31 08:20:05

Turns out I was excluding some required hidden fields from my POST command.

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] Post message with WWW::Mechanize for application/x-www-form-urlencoded

  • 2019-09-17 13:11:34
  • James Finnegan
  • 66 View
  • 0 Score
  • 1 Answer
  • Tags:   perl

3 Answered Questions

1 Answered Questions

How to search for text in html-document with Mechanize?

1 Answered Questions

3 Answered Questions

[SOLVED] Transparently Handling GZip Encoded content with WWW::Mechanize

1 Answered Questions

1 Answered Questions

[SOLVED] WWW::Mechanize in Perl, Script Gets Killed

  • 2012-07-31 17:21:33
  • Neon Flash
  • 778 View
  • 0 Score
  • 1 Answer
  • Tags:   perl www-mechanize

2 Answered Questions

[SOLVED] perl WWW::Mechanize, link redirect problem

Sponsored Content