2008/05/22
あれは HTML entity というのか
by
菊地時夫
—
posted at
2008-05-22 15:47
last modified
2008-05-22 15:55
&Xyz; とか書いて、ラテン文字とか鍵カッコとか、入力できなかったり文字コード集合に無かったり、タグと間違えないようにするやつ。
Python では htmlentitydefs というところに表(辞書)があるので、これを使えばよろしい。
プログラム例:
from htmlentitydefs import name2codepoint as table
def decode(s):
def r(m):
x = m.group(1)
if x.isdigit():
return unichr(int(x))
elif x in table:
return unichr(table[x])
return x
#
s = unicode(s)
return re.sub(r'&(.*?);', r, s)
- Category(s)
- なんでも
- The URL to Trackback this entry is:
- http://sango.lab.tkikuchi.net/Members/tkikuchi/30e130e2/3042308c306f-html-entity-306830443046306e304b/tbping
- mod_python
- ¦
- Main
- ¦
- サーバモニタ