我有以下回溯游戏列表.xml我试图从使用lxml的findall()返回游戏元素。我希望它返回与我正在搜索的标题相近的匹配项,甚至基于我正在搜索的标题的一部分。在
<gameList>
<game id="2652" source="ScreenScraper">
<path>/home/pi/RetroPie/roms/snes/2020 Super Baseball (U).smc</path>
<name>SUPER BASEBALL 2020</name>
<desc>* shortened *</desc>
<image>/home/pi/RetroPie/media/snes/2020 Super Baseball (U)- image.png</image>
<marquee/>
<video>/home/pi/RetroPie/media/snes/2020 Super Baseball (U)- video.mp4</video>
<thumbnail/>
<rating>0.9</rating>
<releasedate>19930713T000000</releasedate>
<developer>Pallas</developer>
<publisher>SNK</publisher>
<genre>Sports</genre>
<players>1-2</players>
</game>
</gameList>
所以我要找的东西会返回与我正在搜索的标题匹配的游戏,在“超级棒球”的例子中,上面的内容应该被返回(整个游戏元素)。思想?我尝试过xpath和其他一些东西,但我缺乏使其按预期工作的能力。在
比如:
^{pr2}$当然不会有任何回报。我可以一个接一个地浏览游戏,寻找精确的匹配,但这似乎很慢,我也觉得必须有一个更简单的方法来做到:
for game in root:
strName = ""
for ele in game:
if ele.tag == "name":
strName = str(ele.text)
if strName.lower() == gameName.lower():
# at this point, game would be the element
也许还有一些正则表达式fu可以用于上面的查找部分名称匹配。不管怎样,任何帮助都会很好。谢谢!在
目前没有回答
相关问题 更多 >
编程相关推荐