亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python 中多次打?。?/h1>

python 中多次打???

當年話下 2024-01-27 14:40:59
  from simplified_scrapy import SimplifiedDoc, utils    #simplified_scrapy is framework for extrcting data    xml = utils.getFileContent('check_in.xml')    doc = SimplifiedDoc(xml)    #SimplifiedDoc is a library for parsing data such as HTML and XML        nodes = doc.select('air:EDS_AirCheckInRQ').children    print (nodes.tag)        for x in nodes:        print((doc.select('air:EDS_AirCheckInRQ')['Version']),(doc.select('com:Source')))                      Here is my output:-    4.000 {'tag': 'com:Source', 'AirlineVendorID': 'CM'}    4.000 {'tag': 'com:Source', 'AirlineVendorID': 'CM'}    4.000 {'tag': 'com:Source', 'AirlineVendorID': 'CM'}    4.000 {'tag': 'com:Source', 'AirlineVendorID': 'CM'}    4.000 {'tag': 'com:Source', 'AirlineVendorID': 'CM'}    4.000 {'tag': 'com:Source', 'AirlineVendorID': 'CM'}這是我的 python 代碼,我只想在其中打印一次,但是當我運行它時,它會給出打印多次的輸出。我只想打印一次。誰能幫我解決為什么打印多次而不是一次?
查看完整描述

2 回答

?
慕姐8265434

TA貢獻1813條經驗 獲得超2個贊

如果你有你的print()inside ,for x in nodes:它會打印每個xin nodes。只需刪除 for 循環,您甚至沒有x在循環中使用。



查看完整回答
反對 回復 2024-01-27
?
江戶川亂折騰

TA貢獻1851條經驗 獲得超5個贊

您正在循環打印。擺脫這個:

for?x?in?nodes:
????????print((doc.select('air:EDS_AirCheckInRQ')['Version']),(doc.select('com:Source')))

據我了解,您正在嘗試從節點中提取一些信息您可以嘗試以下操作:

for?x?in?nodes:
????????print((x.select('air:EDS_AirCheckInRQ')['Version']),(x.select('com:Source')))

但這可能不起作用,因為我不知道您正在使用哪些數據。


查看完整回答
反對 回復 2024-01-27
  • 2 回答
  • 0 關注
  • 176 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號