Crawler breaks when description span node is missing

Issue #125 resolved
sher afgan created an issue

In api version >= 2.1 when an an anime doesn't contain the synopsis, the crawler breaks when it tries to add the background.

The fix is simple, just need to check if the node exists before retrieving its related nodes.

This is what I am using.

# Background
$animerecord->setBackground('No background information has been added to this title.');
$extracted = $crawler->filterXPath('//span[@itemprop="description"]');
if($extracted->count() > 0) {
    preg_match('/div>Background<\/h2>(.+?)<div/s', $extracted->parents()->html(), $matches);
    if (strpos($matches[0], 'No background information') !== false) {
        $animerecord->setBackground('No background information has been added to this title.');
    } else {
        $animerecord->setBackground(trim($matches[1]));
    }
}

For sample case you can use https://myanimelist.net/anime/31861/Tenchi_Muyou_Ryououki_4th_Season or any anime where synopsis or more specific

<span itemprop="description"> ... </span>

is missing.

Comments (3)

  1. Ratan Dhawtal

    Background != Synopsis.

    Synopsis contains a brief summary. Background contains background info like how the mangaka was inspired to make it.

    Anyway it looks like MAL changed the behavior.

  2. Log in to comment