1

when i use this script , its working fine i use HTML::TreeBuilder to parse html from a site

#!/usr/bin/perl -w
use LWP::Simple;
use HTML::TreeBuilder;

use open ':std', ':encoding(UTF-8)';
my $base='https://myanimelist.net';
my $url="/anime/35849/Darling_in_the_FranXX";
my $page = get($base.$url) or die $!;
my $p = HTML::TreeBuilder->new_from_content( $page );

my @trips= $p->look_down(_tag=>'span',itemprop=>'description')->as_text;
foreach my $trip (@trips){
   print $trip;
}

but when i add it to this script it doesn't work

#!/usr/bin/perl -w
use LWP::Simple;
use HTML::TreeBuilder;
my $ua = LWP::UserAgent->new();


my $mal = "https://myanimelist.net/search/all?q=darling";
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/ ) {
print ("https://myanimelist.net/$link\n");

use open ':std', ':encoding(UTF-8)';
my $base='https://myanimelist.net';
$fullink = "$link";
my $page = get($base.$fullink) or die $!;
my $p = HTML::TreeBuilder->new_from_content( $page );

my @trips= $p->look_down(_tag=>'span',itemprop=>'description')->as_text;
foreach my $trip (@trips){
   print $trip;
}
}
}

and i get this error code :

Invalid argument at name.pl line 19.

is there any way to fix it?

2
  • Well done on taking our advice and switching to a parser! :) Now if you want to learn Perl (as opposed to just solving this problem and moving on), I invite you to post you final program to Code Review when it works and tag it with perl and beginner. We'll give you some advice on how to improve it. Commented Apr 26, 2018 at 9:14
  • ok but it steel need more work Commented Apr 26, 2018 at 11:19

1 Answer 1

3

There problem is here. Looks like you are missing anime:

my $page = get($base.$fullink) or die $!;

Try to replace it with:

my $url = $base.'/anime/'.$fullink;
my $page = get($url) or die $!;

Or replace:

my $base='https://myanimelist.net';

with

my $base='https://myanimelist.net/anime/';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.