这是演示如何执行此操作的示例代码。该代码将在程序目录中创建captcha.jpg文件,因此您可以检查它并在此之后输入 CAPTCHA:
use strict;
use warnings;
use FindBin qw($Bin);
#use HTML::TreeBuilder::XPath;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->agent_alias("Windows IE 6");
$mech->get(
"http://epaper.dfdaily.com/dfzb/page/1/2013-08/17/A01/20130817A01_pdf.pdf");
#you don't need commented code
#because CAPTCHA URL is always the same for this site
#my $tree = HTML::TreeBuilder->new_from_content( $mech->content() );
#my ($src) = $tree->findvalues('//img[@id="checkcode"]');
$mech->get("http://203.156.244.168:9000/validatecodegen");
open my $fh, ">:raw", "$Bin/captcha.jpg" or die $!;
print {$fh} $mech->content();
close $fh;
$mech->back();
print "Input CAPTCHA: ";
my $code = <>;
chomp $code;
$mech->submit_form(
with_fields => {
checkCode => $code,
},
button => "Submit",
);
$mech->save_content("$Bin/result.pdf");