Crawler breaks when description span node is missing
Issue #125
resolved
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)
-
-
- changed status to resolved
Create check if node "background" exists instead of displaying a crash.
This issue fixes
#125→ <<cset a35951f644c5>>
-
Create check if node "background" exists instead of displaying a crash.
This issue fixes
#125→ <<cset f1c908b010bb>>
- Log in to comment
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.