diff options
-rw-r--r-- | src/Readability.php | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/Readability.php b/src/Readability.php index d44052d..2f8b22f 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -782,16 +782,10 @@ class Readability */ private function removeScripts(DOMDocument $dom) { - $toRemove = ['script', 'noscript']; - - foreach ($toRemove as $tag) { - while ($script = $dom->getElementsByTagName($tag)) { - if ($script->item(0)) { - $script->item(0)->parentNode->removeChild($script->item(0)); - } else { - break; - } - } + foreach (['script', 'noscript'] as $tag) { + $nodes = $dom->getElementsByTagName($tag); + foreach (iterator_to_array($nodes) as $node) + NodeUtility::removeNode($node); } } |