MCPcopy Index your code
hub / github.com/csev/py4e / insert_after

Method insert_after

code3/bs4/element.py:387–404  ·  view source on GitHub ↗

Makes the given element the immediate successor of this one. The two elements will have the same parent, and the given element will be immediately after this one.

(self, successor)

Source from the content-addressed store, hash-verified

385 parent.insert(index, predecessor)
386
387 def insert_after(self, successor):
388 """Makes the given element the immediate successor of this one.
389
390 The two elements will have the same parent, and the given element
391 will be immediately after this one.
392 """
393 if self is successor:
394 raise ValueError("Can't insert an element after itself.")
395 parent = self.parent
396 if parent is None:
397 raise ValueError(
398 "Element has no parent, so 'after' has no meaning.")
399 # Extract first so that the index won't be screwed up if they
400 # are siblings.
401 if isinstance(successor, PageElement):
402 successor.extract()
403 index = parent.index(self)
404 parent.insert(index+1, successor)
405
406 def find_next(self, name=None, attrs={}, text=None, **kwargs):
407 """Returns the first item that matches the given criteria and

Callers 1

test_insert_afterMethod · 0.45

Calls 3

extractMethod · 0.45
indexMethod · 0.45
insertMethod · 0.45

Tested by 1

test_insert_afterMethod · 0.36