From 276bec56e07eeecb9c072b47111ef7882fed7aeb Mon Sep 17 00:00:00 2001 From: Andres Rey Date: Tue, 22 Nov 2016 09:44:07 +0000 Subject: Added a boolean to check if the result of the operation actually has content or it failed to get it. --- src/HTMLParser.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/HTMLParser.php b/src/HTMLParser.php index 6f80984..4d0a271 100644 --- a/src/HTMLParser.php +++ b/src/HTMLParser.php @@ -346,7 +346,7 @@ class HTMLParser * * @param array $nodes * - * @return DOMDocument + * @return DOMDocument|bool */ private function rateNodes($nodes) { @@ -508,6 +508,8 @@ class HTMLParser $siblingScoreThreshold = max(10, $topCandidate->getContentScore() * 0.2); $siblings = $topCandidate->getParent()->getChildren(); + $hasContent = false; + /** @var Readability $sibling */ foreach ($siblings as $sibling) { $append = false; @@ -536,6 +538,8 @@ class HTMLParser } if ($append) { + $hasContent = true; + if (!in_array(strtolower($sibling->getTagName()), $this->alterToDIVExceptions)) { /* * We have a node that isn't a common block level element, like a form or td tag. @@ -558,7 +562,11 @@ class HTMLParser } } - return $articleContent; + if ($hasContent) { + return $articleContent; + } else { + return false; + } } /** -- cgit v1.2.3