def ensure_soup(value, parser=None):
 if isinstance(value, BeautifulSoup):
  return value.find()
 if isinstance(value, Tag):
  return value
 if isinstance(value, list):
  return [ensure_soup(item, parser=parser) for item in value]
 parsed = BeautifulSoup(value, features=parser)
 return parsed.find()

def ensure_soup ( value , parser = None ) : if isinstance ( value , BeautifulSoup ) : return value . find ( ) if isinstance ( value , Tag ) : return value if isinstance ( value , list ) : return [ ensure_soup ( item , parser = parser ) for item in value ] parsed = BeautifulSoup ( value , features = parser ) return parsed . find ( )
coerce a value to tag .