diff options
author | Andres Rey <[email protected]> | 2016-11-22 09:44:07 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2016-11-22 09:44:07 +0000 |
commit | 276bec56e07eeecb9c072b47111ef7882fed7aeb (patch) | |
tree | fa75e2b90bbdbbfe637ad3968c83e9e13818405f /src | |
parent | 34f560cdb940d4bee5a072f63b03fefbe447b237 (diff) |
Added a boolean to check if the result of the operation actually has content or it failed to get it.
Diffstat (limited to 'src')
-rw-r--r-- | src/HTMLParser.php | 12 |
1 files changed, 10 insertions, 2 deletions
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; + } } /** |