def clone_bs4_elem(el):
if isinstance(el, NavigableString):<EOL><INDENT>return type(el)(el)<EOL><DEDENT>copy = Tag(None, el.builder, el.name, el.namespace, el.nsprefix)<EOL>copy.attrs = dict(el.attrs)<EOL>for attr in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>setattr(copy, attr, getattr(el, attr))<EOL><DEDENT>for child in el.contents:<EOL><INDENT>copy.append(clone_bs4_elem(child))<EOL><DEDENT>return copy<EOL>
Clone a bs4 tag before modifying it.

    Code from `http://stackoverflow.com/questions/23057631/clone-element-with
    -beautifulsoup`