第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用python創(chuàng)建搜索引擎(僅從XML文件搜索)

使用python創(chuàng)建搜索引擎(僅從XML文件搜索)

回首憶惘然 2021-03-28 14:58:23
我在XML文件中有類似這樣的詳細(xì)信息<note><id>51</id><Name>Jani</Name><city>Frankfurt</city><IQ>Intelligent</IQ></note><note><id>71</id><Name>Peter</Name><city>Paris</city><IQ>Average</IQ></note><note><id>81</id><Name>Asho</Name><city>Paris</city><IQ>Intelligent</IQ></note>有了這些細(xì)節(jié),我想實(shí)現(xiàn)一個(gè)搜索引擎,該引擎應(yīng)使用戶能夠搜索'Intelligent'文件中的所有人員。請(qǐng)建議我在python中執(zhí)行此操作的最佳方法。
查看完整描述

2 回答

?
慕少森

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊

使用lxml和XPath:


from StringIO import StringIO

from lxml import etree


xml = """<root>

<note>

<id>51</id>

<Name>Jani</Name>

<city>Frankfurt</city>

<IQ>Intelligent</IQ>

</note>


<note>

<id>71</id>

<Name>Peter</Name>

<city>Paris</city>

<IQ>Average</IQ>

</note>


<note>

<id>81</id>

<Name>Asho</Name>

<city>Paris</city>

<IQ>Intelligent</IQ>

</note>


</root>"""


tree = etree.parse(StringIO.StringIO(xml))

for note in tree.xpath("//note[IQ='Intelligent']"):

    print note.getchildren()[1].tag + "=" + note.getchildren()[1].text

打?。?/p>


Name=Jani

Name=Asho


查看完整回答
反對(duì) 回復(fù) 2021-04-01
  • 2 回答
  • 0 關(guān)注
  • 185 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)