diff --git a/readability/readability.py b/readability/readability.py index 255e877..a03f9db 100755 --- a/readability/readability.py +++ b/readability/readability.py @@ -212,7 +212,9 @@ class Document: else: output = document_fromstring('
') best_elem = best_candidate['elem'] - for sibling in best_elem.getparent().getchildren(): + parent = best_elem.getparent() + siblings = parent.getchildren() if parent else [best_elem] + for sibling in siblings: # in lxml there no concept of simple text # if isinstance(sibling, NavigableString): continue append = False diff --git a/tests/test_article_only.py b/tests/test_article_only.py index ab49233..882d346 100644 --- a/tests/test_article_only.py +++ b/tests/test_article_only.py @@ -50,3 +50,14 @@ class TestArticleOnly(unittest.TestCase): doc = Document(sample) res = doc.summary(html_partial=True) self.assertEqual('
' + ' ' + '

1234567890123456789012345

' + ' ' + '' + ) + doc = Document(sample) + doc.summary()