Python 处理unicode
我是为runescape维基开发的。但是,每当我遇到unicode的问题时,让我们假设一个页面如下所示:Python 处理unicode,python,mediawiki-api,Python,Mediawiki Api,我是为runescape维基开发的。但是,每当我遇到unicode的问题时,让我们假设一个页面如下所示: This is a page, that has words To go here to there follow these directions: Backwards « Forwards That is all 如果只是执行mwhear.edit('Page over'),我将收到一个unicode错误 我尝试通过以下方式解决此问题: text = mwhair.edit('Page
This is a page, that has words
To go here to there follow these directions:
Backwards « Forwards
That is all
如果只是执行mwhear.edit('Page over')
,我将收到一个unicode错误
我尝试通过以下方式解决此问题:
text = mwhair.edit('Page above').encode('ascii','xmlcharrefreplace')
mwhair.save('Page above',text=text)
这似乎是一个解决方案,因为不会出现错误,但会更改页面的某些内容,例如将行更改为:
Backwards « Forwards
这不会影响任何链接、图片或实际页面输出,但使bot看起来好像有错误。有什么事我搞砸了还是不知道?(我使用的是python 2.7.3)在您的计算机上,您有:
'text':text,
text
在这一点上是Unicode,因此您可能希望在这一点上对其进行编码。我假设MediaWiki想要UTF-8:
'text': text.encode('utf-8'),
这很有效,我知道这是少了一些小东西。谢谢