code: def _extract_title(self):
          
  
          if self.title:
              return
  
          for pattern in self.config.title:
              items = self.parsed_tree.xpath(pattern)
  
              if not items:
                  continue
  
              if isinstance(items, basestring):
                  # In case xpath returns only one element.
                  items = [items]
  
              if len(items) == 1:
                  item = items[0]
  
                  try:
                      self.title = item.text.strip()
  
                  except AttributeError:
                      # '_ElementStringResult' object has no attribute 'text'
                      self.title = unicode(item).strip()
  
                  LOGGER.info(u'Title extracted: “%s”.', self.title,
                              extra={'siteconfig': self.config.host})
  
                  try:
                      item.getparent().remove(item)
  
                  except TypeError:
                      # Argument 'element' has incorrect type (expected
                      # lxml.etree._Element, got _ElementStringResult)
                      pass
  
                  except AttributeError, e:
                      if u'NoneType' not in unicode(e):
                          LOGGER.exception(u'Could not remove title from '
                                           u'document.',
                                           extra={'siteconfig': self.config.host})
                      # implicit: else: this is begnin
  
                  except:
                      LOGGER.exception(u'Could not remove title from document.',
                                       extra={'siteconfig': self.config.host})
  
                  # Exit at first item found.
                  break
  
              else:
                  LOGGER.warning(u'Multiple items (%s) for title pattern %s.',
                                 items, pattern,
                                 extra={'siteconfig': self.config.host})
docs: Extract the title and remove it from the document.
  
          If title has already been extracted, this method will do nothing.
  
          If removal cannot happen or fails, the document is left untouched.