perl检索机械化后的页面细节:: POST

问题描述:

我想从网站收集数据。一些反模式使寻找合适的表单对象变得困难,但我解决了这个问题。我正在使用post方法来解决一些JavaScript作为包装提交表单的问题。我的问题似乎是从mechanize-> post方法获得结果。perl检索机械化后的页面细节:: POST

这里是我的代码的缩写版本。

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. 

}

的数据,我从我的最后的打印语句得到的是从德原始URL中的数据不是页面的POST命令应该带我去。我做错了什么?

非常感谢

更新

我没有Firefox的安装,所以我回避WWW::Mechanize::Firefox故意。

+1

试试:'$ mech-> response-> content;'或'$ mech-> response-> decoded_content;' – jm666

+0

谢谢jm666。 我收到$ mech-> content的回应; $ mech->响应 - >内容;和$ mech-> response-> decoded_content;但是他们都是开始页面 - 而不是POST命令应该带给我的页面。 – MicrobicTiger

+0

你的代码没有任何明显的错误,所以我怀疑这个问题将会针对你正在努力实现的网站。因此,任何人都不可能用你提供的信息来帮助你。 – Miller

原来我从POST命令中排除了一些必需的隐藏字段。