def fragments_fromstring(html, no_leading_text=False, base_url=None, parser=None, **kw):
 if (parser is None):
  parser = html_parser
 if isinstance(html, bytes):
  if (not _looks_like_full_html_bytes(html)):
   html = (('<html><body>'.encode('ascii') + html) + '</body></html>'.encode('ascii'))
 elif (not _looks_like_full_html_unicode(html)):
  html = ('<html><body>%s</body></html>' % html)
 doc = document_fromstring(html, parser=parser, base_url=base_url, **kw)
 assert (_nons(doc.tag) == 'html')
 bodies = [e for e in doc if (_nons(e.tag) == 'body')]
 assert (len(bodies) == 1), ('too many bodies: %r in %r' % (bodies, html))
 body = bodies[0]
 elements = []
 if (no_leading_text and body.text and body.text.strip()):
  raise etree.ParserError(('There is leading text: %r' % body.text))
 if (body.text and body.text.strip()):
  elements.append(body.text)
 elements.extend(body)
 return elements

def fragments_fromstring ( html , no_leading_text = False , base_url = None , parser = None , ** kw ) : if ( parser is None ) : parser = html_parser if isinstance ( html , bytes ) : if ( not _looks_like_full_html_bytes ( html ) ) : html = ( ( '<html><body>' . encode ( 'ascii' ) + html ) + '</body></html>' . encode ( 'ascii' ) ) elif ( not _looks_like_full_html_unicode ( html ) ) : html = ( '<html><body>%s</body></html>' % html ) doc = document_fromstring ( html , parser = parser , base_url = base_url , ** kw ) assert ( _nons ( doc . tag ) == 'html' ) bodies = [ e for e in doc if ( _nons ( e . tag ) == 'body' ) ] assert ( len ( bodies ) == 1 ) , ( 'too many bodies: %r in %r' % ( bodies , html ) ) body = bodies [ 0 ] elements = [ ] if ( no_leading_text and body . text and body . text . strip ( ) ) : raise etree . ParserError ( ( 'There is leading text: %r' % body . text ) ) if ( body . text and body . text . strip ( ) ) : elements . append ( body . text ) elements . extend ( body ) return elements
parses several html elements .