这是我要更改的脚本
#!/usr/bin/perl
use if $^O eq "MSWin32", Win32::Console::ANSI;
use Term::ANSIColor;
use LWP::UserAgent;
use LWP::Simple;
use HTML::TreeBuilder;
my $ua = LWP::UserAgent->new();
use open ':std', ':encoding(UTF-8)';
for ( $n = 0 ) {
$search_quote = "Darling";
my $mal = "https://myanimelist.net/search/all?q=$search_quote";
my $response = $ua->request(HTTP::Request->new(GET => $mal));
my $rrs = $response->content;
while ( $rrs =~ m/href=\"https:\/\/myanimelist.net\/anime\/(.*?)\" class=\"hoverinfo_trigger fw-b fl-l\"/g ) {
my $link = $1;
if ( $link !~ /video|season?_location=mal_h_m/ ) {
$n += 1;
print item("$n"),
item("ANIME LINK"),
("https://myanimelist.net/$link\n");
my $base = 'https://myanimelist.net/anime/';
my $page = get($base . $link) or die $!;
my $p = HTML::TreeBuilder->new_from_content($page);
my @trips = $p->look_down(_tag=>'span',itemprop=>'name')->as_text;
foreach my $trip ( @trips ) {
print item("-"), item("ANIME NAME"), "$trip\n\n";
}
}
}
animelink();
}
sub animelink {
print colored ("[!] What Anime you want to see?\n", "red");
print colored ("[!] Number :", "red");
my $animenumber = <STDIN>;
chomp($animenumber);
}
sub item {
my $n = shift // '+';
return
color('bold white'), " [",
color('bold blue'), "$n",
color('bold white'), "] ",
color("bold white");
}
我需要一种方法来使用数字$n
选择已解析的链接。
我试过用
if ( $animenumber eq $n )
但它不起作用。
如何从已解析的链接中选择一个链接?