大佬教程收集整理的这篇文章主要介绍了将XML非法和char转换为utf8 – python,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在以下位置有一个XML和HTML字符引用列表:https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references.
但是,有些内容在该列表中根本没有定义,但它们在较旧的HTML脚本中使用.当我处理来自http://www.d.umn.edu/~tpederse/data.html的Senseval-2格式(带有修复)数据集时,我会遇到以下单词,它会破坏我的脚本,该脚本试图使用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 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,@R_@R_772_11280@_8620@n 113
在您链接到的页面(http://www.d.umn.edu/~tpederse/data.html)上,它说:
因此,尽管该文档看起来非常像XML,但它不是XML,发布它的人也非常清楚这一点.
以上是大佬教程为你收集整理的将XML非法和char转换为utf8 – python全部内容,希望文章能够帮你解决将XML非法和char转换为utf8 – python所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。