in reply to Re^3: Running JavaScript from within Perl
in thread Running JavaScript from within Perl
Here's a short example using Mojo::UserAgent:
#!/usr/bin/perl use strict; use warnings; use Mojo::UserAgent; # your URL my $url = 'https://public-api.wordpress.com/rest/v1/read/feed/http%3A%2F%2Fthe-a +rt-of-autism.com%2Ffeed'; # create a Mojo:UserAgent my $ua = Mojo::UserAgent->new; # use $ua to get the url and assign the value of 'subscriber_count' in + the json # to avariable, $subscribers my $subscribers = $ua->get( $url )->result->json->{subscribers_count}; # print the variable to screen print "Number of subscribers: $subscribers\n";
Running this returns:
Number of subscribers: 181
To install the required module, from the command line:
cpanm Mojolicious (or if you don't have cpanm) cpan Mojolicious
|
---|
In Section
Seekers of Perl Wisdom