def extract_text_in(html, starttag):
 try:
  (_, html) = html.split(starttag, 1)
 except ValueError:
  return
 level = 0
 parts = []
 pos = 0
 for match in DIV_RE.finditer(html):
  if match.group(1):
   level -= 1
   if (level == 0):
    pos = match.end()
  else:
   if (level == 0):
    parts.append(html[pos:match.start()])
   level += 1
  if (level == (-1)):
   parts.append(html[pos:match.start()])
   break
 else:
  print(u'no closing tag found!')
  return
 return u''.join(parts)

def extract_text_in ( html , starttag ) : try : ( _ , html ) = html . split ( starttag , 1 ) except ValueError : return level = 0 parts = [ ] pos = 0 for match in DIV_RE . finditer ( html ) : if match . group ( 1 ) : level -= 1 if ( level == 0 ) : pos = match . end ( ) else : if ( level == 0 ) : parts . append ( html [ pos : match . start ( ) ] ) level += 1 if ( level == ( - 1 ) ) : parts . append ( html [ pos : match . start ( ) ] ) break else : print ( u'no closing tag found!' ) return return u'' . join ( parts )
extract the text from a <div> tag in the html starting with starttag .