Skip to content

Commit cba19f2

Browse files
committed
Fix issue with trying to drop root node
remove_unlikely_candidates would try to drop_tree the root node if it deemed it an unlikely candidate. This prevents that from happening.
1 parent 18fa6b5 commit cba19f2

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

readability/readability.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ def remove_unlikely_candidates(self):
295295
for elem in self.html.iter():
296296
s = "%s %s" % (elem.get('class', ''), elem.get('id', ''))
297297
#self.debug(s)
298-
if REGEXES['unlikelyCandidatesRe'].search(s) and (not REGEXES['okMaybeItsACandidateRe'].search(s)) and elem.tag != 'body':
298+
if (REGEXES['unlikelyCandidatesRe'].search(s) and
299+
(not REGEXES['okMaybeItsACandidateRe'].search(s)) and
300+
elem.tag != 'body' and
301+
elem.getparent() is not None
302+
):
299303
self.debug("Removing unlikely candidate - %s" % describe(elem))
300304
elem.drop_tree()
301305

0 commit comments

Comments
 (0)