我正在从 .txt 加载数据以进行抓取。但是,URL 要求我分解该变量并对其执行 +/- 2。例如,如果值为 2342,我需要为 URL 创建 2340 和 2344。
我猜测如何分解它:
$args{birth_year} = ($args{birth_year} - 2) . '-' . ($args{birth_year} + 2);
然后如何将其放入 URL 中?
这是代码的相关部分:
use strict;
use warnings;
use WWW::Mechanize::Firefox;
use Data::Dumper;
use LWP::UserAgent;
use JSON;
use CGI qw/escape/;
use HTML::DOM;
open(my $l, 'locations2.txt') or die "Can't open locations: $!";
while (my $line = <$l>) {
chomp $line;
my %args;
@args{qw/givenname surname birth_place birth_year gender race/} = split /,/, $line;
$args{birth_year} = ($args{birth_year} - 2) . '-' . ($args{birth_year} + 2);
my $mech = WWW::Mechanize::Firefox->new(create => 1, activate => 1);
$mech->get("https://familysearch.org/search/collection/index#count=20&query=%2Bgivenname%3A$args{givenname}20%2Bsurname%3A$args{surname}20%2Bbirth_place%3A$args{birth_place}%20%2Bbirth_year%3A1910-1914~%20%2Bgender%3A$args{gender}20%2Brace%3A$args{race}&collection_id=2000219");
例如
输入是:
Benjamin,Schuvlein,Germany,1912,M,White
所需的网址是: