Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9268225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:45:21+00:00 2026-06-18T14:45:21+00:00

I am interested in writing a perl script that goes to the following link

  • 0

I am interested in writing a perl script that goes to the following link and extracts the number 1975: https://familysearch.org/search/collection/results#count=20&query=%2Bevent_place_level_1%3ACalifornia%20%2Bevent_place_level_2%3A%22San%20Diego%22%20%2Bbirth_year%3A1923-1923~%20%2Bgender%3AM%20%2Brace%3AWhite&collection_id=2000219

That website is the amount of white men born in the year 1923 who live in San Diego County, California in 1940. I am trying to do this in a loop structure to generalize over multiple counties and birth years.

In the file, locations.txt, I put the list of counties, such as San Diego County.

The current code runs, but instead of the # 1975, it displays unknown. The number 1975 should be in $val\n.

I would very much appreciate any help!

#!/usr/bin/perl

use strict;

use LWP::Simple;

open(L, "locations26.txt");

my $url = 'https://familysearch.org/search/collection/results#count=20&query=%2Bevent_place_level_1%3A%22California%22%20%2Bevent_place_level_2%3A%22%LOCATION%%22%20%2Bbirth_year%3A%YEAR%-%YEAR%~%20%2Bgender%3AM%20%2Brace%3AWhite&collection_id=2000219';

open(O, ">out26.txt");
 my $oldh = select(O);
 $| = 1;
 select($oldh);
 while (my $location = <L>) {
     chomp($location);
     $location =~ s/ /+/g;
      foreach my $year (1923..1923) {
                 my $u = $url;
                 $u =~ s/%LOCATION%/$location/;
                 $u =~ s/%YEAR%/$year/;
                 #print "$u\n";
                 my $content = get($u);
                 my $val = 'unknown';
                 if ($content =~ / of .strong.([0-9,]+)..strong. /) {
                         $val = $1;
                 }
                 $val =~ s/,//g;
                 $location =~ s/\+/ /g;
                 print "'$location',$year,$val\n";
                 print O "'$location',$year,$val\n";
         }
     }

Update: API is not a viable solution. I have been in contact with the site developer. The API does not apply to that part of the webpage. Hence, any solution pertaining to JSON will not be applicbale.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:45:22+00:00Added an answer on June 18, 2026 at 2:45 pm

    If you use your browser’s development tools, you can clearly see the JSON request that the page you link to uses to get the data you’re looking for.

    This program should do what you want. I’ve added a bunch of comments for readability and explanation, as well as made a few other changes.

    use warnings;
    use strict;
    use LWP::UserAgent;
    use JSON;
    use CGI qw/escape/;
    
    # Create an LWP User-Agent object for sending HTTP requests.
    my $ua = LWP::UserAgent->new;
    
    # Open data files
    open(L, 'locations26.txt') or die "Can't open locations: $!";
    open(O, '>', 'out26.txt') or die "Can't open output file: $!";
    
    # Enable autoflush on the output file handle
    my $oldh = select(O);
    $| = 1;
    select($oldh);
    
    while (my $location = <L>) {
        # This regular expression is like chomp, but removes both Windows and
        # *nix line-endings, regardless of the system the script is running on.
        $location =~ s/[\r\n]//g;
        foreach my $year (1923..1923) {
            # If you need to add quotes around the location, use "\"$location\"".
            my %args = (LOCATION => $location, YEAR => $year);
    
            my $url = 'https://familysearch.org/proxy?uri=https%3A%2F%2Ffamilysearch.org%2Fsearch%2Frecords%3Fcount%3D20%26query%3D%252Bevent_place_level_1%253ACalifornia%2520%252Bevent_place_level_2%253A^LOCATION^%2520%252Bbirth_year%253A^YEAR^-^YEAR^~%2520%252Bgender%253AM%2520%252Brace%253AWhite%26collection_id%3D2000219';
            # Note that values need to be doubly-escaped because of the
            # weird way their website is set up (the "/proxy" URL we're
            # requesting is subsequently loading some *other* URL which
            # is provided to "/proxy" as a URL-encoded URL).
            #
            # This regular expression replaces any ^WHATEVER^ in the URL
            # with the double-URL-encoded value of WHATEVER in %args.
            # The /e flag causes the replacement to be evaluated as Perl
            # code. This way I can look data up in a hash and do URL-encoding
            # as part of the regular expression without an extra step.
            $url =~ s/\^([A-Z]+)\^/escape(escape($args{$1}))/ge;
            #print "$url\n";
    
            # Create an HTTP request object for this URL.
            my $request = HTTP::Request->new(GET => $url);
            # This HTTP header is required. The server outputs garbage if
            # it's not present.
            $request->push_header('Content-Type' => 'application/json');
            # Send the request and check for an error from the server.
            my $response = $ua->request($request);
            die "Error ".$response->code if !$response->is_success;
            # The response should be JSON.
            my $obj = from_json($response->content);
            my $str = "$args{LOCATION},$args{YEAR},$obj->{totalHits}\n";
            print O $str;
            print $str;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm interested in writing a very generic script that I can include into my
I'm interested in writing a PHP script (I do welcome language-agnostic suggestions) that would
I am interested in writing an application that overlays a small heads up display
I am interested in writing a trigger that would ignore queries from a specific
I'm interested in writing arrays of bytes to disk using BufferedWriter.write() . But that
I am interested in writing an application that will take in an excel document
I've been interested in writing an application that will show how to fit boxes
I am interested in writing a Java program which does the following. Attach to
I am interested in writing apps that connect to the intranet or an extranet.
I'm interested in writing software that runs with as little booting as possible. What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.