在 JSON 中进行 perl API 调用时出现问题
issue taking a perl API call that is in JSON
你好,我在 JSON 中进行 perl API 调用时遇到问题我想从这个 link
中获取所有子域
#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Request;
use LWP::UserAgent;
use HTTP::Response;
use HTTP::Request::Common qw(POST);
use HTTP::Request::Common qw(GET);
use Data::Dumper;
use LWP::Simple;
use JSON qw( decode_json encode_json );
my $ua = LWP::UserAgent->new;
$ua = LWP::UserAgent->new(keep_alive => 1);
$ua->agent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31");
my $url = "https://www.threatcrowd.org/searchApi/v2/domain/report/?domain=fb.com";
my $request = $ua->get($url);
my $response = $request->content;
my $decoded = decode_json($response);
print $decoded->{'subdomains'};
如果 运行 这个脚本得到这个
C:\Users\USER\Desktop>1.pl
ARRAY(0x625c868
如果它真的是一个简单的数组引用(你可以使用Data::Dumper来检查),你需要遍历列表并打印每个element/item:
for my $element (@{ $decoded->{'subdomains'} }){
print "$element\n";
}
@{}
语法是取消引用运算符。它取消引用在其大括号内的变量中保存的数组引用。
有关详细信息,请参阅 Using References section in the perlreftut 文档。
你好,我在 JSON 中进行 perl API 调用时遇到问题我想从这个 link
中获取所有子域#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Request;
use LWP::UserAgent;
use HTTP::Response;
use HTTP::Request::Common qw(POST);
use HTTP::Request::Common qw(GET);
use Data::Dumper;
use LWP::Simple;
use JSON qw( decode_json encode_json );
my $ua = LWP::UserAgent->new;
$ua = LWP::UserAgent->new(keep_alive => 1);
$ua->agent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31");
my $url = "https://www.threatcrowd.org/searchApi/v2/domain/report/?domain=fb.com";
my $request = $ua->get($url);
my $response = $request->content;
my $decoded = decode_json($response);
print $decoded->{'subdomains'};
如果 运行 这个脚本得到这个
C:\Users\USER\Desktop>1.pl
ARRAY(0x625c868
如果它真的是一个简单的数组引用(你可以使用Data::Dumper来检查),你需要遍历列表并打印每个element/item:
for my $element (@{ $decoded->{'subdomains'} }){
print "$element\n";
}
@{}
语法是取消引用运算符。它取消引用在其大括号内的变量中保存的数组引用。
有关详细信息,请参阅 Using References section in the perlreftut 文档。