0

我想生成一个http请求。我相信以下代码除了当前的我的 $uri 行之外有效,因为我在 google 网站上尝试过(取消注释该行并注释掉当前的 uri 行)。然后我在一个感兴趣的站点上尝试了它,但它失败了。我相信它失败了,部分原因是网页上有一个 javascript。我说它失败是因为在最后一行,它不满足 if 语句,而是死了。如果它没有输入那个 if 语句,我会认为它是成功的。关于如何进行的任何建议?

 #!/usr/bin/perl

 use strict;
 use warnings;
 use LWP::UserAgent;
 use URI::Escape;

 my $uri = "https://familysearch.org/search/collection/results#count=20&query=%2Bgivenname%3ALester%20%2Bsurname%3AYoungblood%20%2Bevent_place_level_1%3AGeorgia%20%2Bevent_place_level_2%3AWhitfield%20%2Bevent_place_level_3%3ACarbondale%20%2Bgender%3AM&collection_id=2000219";
#my $uri = "https://www.google.com";

my $req = HTTP::Request->new( 'GET', $uri );
$req->header( 'Content-Type' => 'application/json' );
my $lwp = LWP::UserAgent->new;
my $res = $lwp->request($req);
if ( not $res->is_success ) { warn "Bad response :("; sleep(1); die; }
4

1 回答 1

1

您需要使用另一个 URL:

#!/usr/bin/perl

use strict;
use warnings;
use LWP::UserAgent;

my $json_uri =
"https://familysearch.org/search/records?count=20&query=%2Bgivenname%3ALester%20%2Bsurname%3AYoungblood%20%2Bevent_place_level_1%3AGeorgia%20%2Bevent_place_level_2%3AWhitfield%20%2Bevent_place_level_3%3ACarbondale%20%2Bgender%3AM&collection_id=2000219";

my $lwp = LWP::UserAgent->new;

my $req = HTTP::Request->new( 'GET', $json_uri );

$req->header( 'Content-Type' => 'application/json' );

my $res = $lwp->request($req);

if ( not $res->is_success ) { warn "Bad response :("; sleep(1); die; }
于 2013-06-10T08:12:43.360 回答