Thursday, 15 September 2011

ajax - Perl - Breaking a variable from the input into two for the url -



ajax - Perl - Breaking a variable from the input into two for the url -

i'm loading info .txt purposes of scraping. however, url requires break variable , +/- 2 it. example, if value 2342, need create 2340 , 2344 purposes of url.

i took guess @ how break up:

$args{birth_year} = ($args{birth_year} - 2) . '-' . ($args{birth_year} + 2);

how set in url?

here's relevant part of code:

utilize strict; utilize warnings; utilize www::mechanize::firefox; utilize data::dumper; utilize lwp::useragent; utilize json; utilize cgi qw/escape/; utilize html::dom; open(my $l, 'locations2.txt') or die "can't open locations: $!"; while (my $line = <$l>) { chomp $line; %args; @args{qw/givenname surname birth_place birth_year gender race/} = split /,/, $line; $args{birth_year} = ($args{birth_year} - 2) . '-' . ($args{birth_year} + 2); $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"); for example

input is:

benjamin,schuvlein,germany,1912,m,white

desired url is:

https://familysearch.org/search/collection/index#count=20&query=%2bgivenname%3abenjamin%20%2bsurname%3aschuvlein%20%2bbirth_place%3agermany%20%2bbirth_year%3a1910-1914~%20%2bgender%3am%20%2brace%3awhite&collection_id=2000219

why can't alter line:

$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");

to this:

$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%3a$args(birth_year)~%20%2bgender%3a$args{gender}20%2brace%3a$args{race}&collection_id=2000219");

note: changed bit:

%3a1910-1914~%20

to this:

%3a$arg(birth_year)~%20

ajax json perl web-scraping mozrepl

No comments:

Post a Comment