code: def replace_rsc_img_chars(document):
      
      image_re = re.compile('http://www.rsc.org/images/entities/(?:h[23]+_)?(?:[ib]+_)?char_([0-9a-f]{4})(?:_([0-9a-f]{4}))?\.gif')
      for img in document.xpath('.//img[starts-with(@src, "http://www.rsc.org/images/entities/")]'):
          m = image_re.match(img.get('src'))
          if m:
              u1, u2 = m.group(1), m.group(2)
              if not u2 and u1 in RSC_IMG_CHARS:
                  rep = RSC_IMG_CHARS[u1]
              else:
                  rep = ('\\u%s' % u1).encode('ascii').decode('unicode-escape')
                  if u2:
                      rep += ('\\u%s' % u2).encode('ascii').decode('unicode-escape')
              if img.tail is not None:
                  rep += img.tail  # Make sure we don't remove any tail text
              parent = img.getparent()
              if parent is not None:
                  previous = img.getprevious()
                  if previous is not None:
                      previous.tail = (previous.tail or '') + rep
                  else:
                      parent.text = (parent.text or '') + rep
                  parent.remove(img)
      return document
docs: Replace image characters with unicode equivalents.