更新 python-elementtree 以克服 xpath 选择器问题
使用 ElementTree 在 xml 中搜索节点的属性时出现错误。
expected path separator ([)
源代码是:
home_team_node = game_node.find( "team/team-metadata[@alignment='home']" )
Stackoverflow 上的这个讨论让我得出结论,我需要更新版本的 ElementTree。
当我列出已安装的软件包时,我看到我有 python-elementtree 版本 1.2.6-14。然而,即使在运行 apt-get update 之后,任何升级 python-elementtree 的努力都会告诉我我已经获得了最新版本。我运行的是 Ubuntu 9.10,所以存储库可能没有 elementtree 1.3。
我可以做什么来升级到 1.3 版本?
I'm getting an error when searching for the attribute of a node in my xml using ElementTree.
expected path separator ([)
The source code is:
home_team_node = game_node.find( "team/team-metadata[@alignment='home']" )
This discussion on Stackoverflow leads me to conclude I need a newer version of ElementTree.
ElementTree XPath - Select Element based on attribute
When I list installed packages I see I have python-elementtree version 1.2.6-14. Yet even after running apt-get update, any effort to upgrade python-elementtree tells me I've got the latest version. I'm running Ubuntu 9.10, so maybe the repositories don't have elementtree 1.3.
What can I do to upgrade to version 1.3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
lxml 是一个非常有用的解析 XML 的库,它具有 ElementTree API 的完整实现。尝试安装它:
然后您需要更改导入语句以使用 lxml 版本而不是捆绑
elementree
。(除非您处于
virtualenv
环境中,否则我会拒绝使用pip
或easy_install
,以避免与 Debian 打包的 Python 库混淆。)lxml is a very useful library for parsing XML, and it has a complete implementation of the ElementTree API. Try installing it with:
You'll then need to change your import statments to use the lxml version instead of the bundled
elementree
.(I would resist using
pip
oreasy_install
unless you're in avirtualenv
environment, to avoid confusion with the Debian-packaged Python libraries.)尝试使用
easy_install
或pip
安装 lxml、ElementTree 或 cElementTree。这些软件包可能比 apt 存储库中的软件包更新。华泰
Try installing lxml, ElementTree or cElementTree with either
easy_install
orpip
. These packages are likely more recent than the ones in theapt
repositories.HTH