13 lines
368 B
Python
13 lines
368 B
Python
|
from bs4.element import NavigableString
|
||
|
|
||
|
|
||
|
def strip_content(tag):
|
||
|
# strip content from all children
|
||
|
children = [strip_content(child) for child in tag.children if not isinstance(child, NavigableString)]
|
||
|
# remove everything from the tag
|
||
|
tag.clear()
|
||
|
for child in children:
|
||
|
# Add back stripped children
|
||
|
tag.append(child)
|
||
|
return tag
|