Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: Running JavaScript from within Perl

by marto (Archbishop)
on Sep 17, 2019 at 02:24 UTC ( #11106276=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11106276]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2019-10-21 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?