有一个 XML 和 HTML 字符引用列表:https ://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references 。
但是,该列表中根本没有定义一些东西,但它们已在较旧的 HTML 脚本中使用。当我处理Senseval-2 format (with fixes)
来自http://www.d.umn.edu/~tpederse/data.html的数据集时,我遇到以下单词,它破坏了我试图用来xml.et.elementTree
解析数据的脚本。
这些词的 unicode 等价物是什么?
&and.
&and.A
&and.B
&and.D
&and.L's
&backquote.alim)
&backquote.ulema
&dash
&dash.
&dash."
&dashq.
°ree.
°ree.C
&ellip
&ellip.
&ellip.0
&ellip.1
&ellip.11
&ellip.2
&ellip.23
&ellip.28
&ellip.38
&ellip.4
&ellip.6
&ellip.64
&ellip.?"
&ellip.two
×.
我的脚本:
import xml.etree.ElementTree as et
s1 = 'train-fix.xml' # from http://www.d.umn.edu/~tpederse/Data/Sval1to2.fix.tar.gz
tree = et.parse(s1)
root = tree.getroot()
给出这个回溯:
Traceback (most recent call last):
File "senseval.py", line 4, in <module>
tree = et.parse(s1)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1182, in parse
tree.parse(source, parser)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse
parser.feed(data)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1642, in feed
self._raiseerror(v)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
raise err
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 41, column 113