summaryrefslogtreecommitdiff
path: root/bs4/element.py
diff options
context:
space:
mode:
Diffstat (limited to 'bs4/element.py')
-rw-r--r--bs4/element.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/bs4/element.py b/bs4/element.py
index e10e100..caa855e 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -255,13 +255,16 @@ class PageElement(object):
self.previous_sibling = self.next_sibling = None
return self
- def _last_descendant(self, is_initialized=True):
+ def _last_descendant(self, is_initialized=True, accept_self=True):
"Finds the last element beneath this object to be parsed."
if is_initialized and self.next_sibling:
- return self.next_sibling.previous_element
- last_child = self
- while isinstance(last_child, Tag) and last_child.contents:
- last_child = last_child.contents[-1]
+ last_child = self.next_sibling.previous_element
+ else:
+ last_child = self
+ while isinstance(last_child, Tag) and last_child.contents:
+ last_child = last_child.contents[-1]
+ if not accept_self and last_child == self:
+ last_child = None
return last_child
# BS3: Not part of the API!
_lastRecursiveChild = _last_descendant