def clone_bs4_elem(el):
 if isinstance(el, NavigableString):
  return type(el)(el)
 copy = Tag(None, el.builder, el.name, el.namespace, el.nsprefix)
 copy.attrs = dict(el.attrs)
 for attr in ('can_be_empty_element', 'hidden'):
  setattr(copy, attr, getattr(el, attr))
 for child in el.contents:
  copy.append(clone_bs4_elem(child))
 return copy

def clone_bs4_elem ( el ) : if isinstance ( el , NavigableString ) : return type ( el ) ( el ) copy = Tag ( None , el . builder , el . name , el . namespace , el . nsprefix ) copy . attrs = dict ( el . attrs ) for attr in ( 'can_be_empty_element' , 'hidden' ) : setattr ( copy , attr , getattr ( el , attr ) ) for child in el . contents : copy . append ( clone_bs4_elem ( child ) ) return copy
clone a bs4 tag before modifying it .