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

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

使用 ElementTree 提取 <content:encoded>

使用 ElementTree 提取 <content:encoded>

小唯快跑啊 2023-02-12 19:12:02
我目前正在嘗試弄清楚如何在 Python 中使用 ElementTree 提取 <content:encoded> 和 </content:encoded> 之間的內容。下面附上的是我目前用來解決這個問題的 Python 代碼。我目前無法提取內容。我想提取“我喜歡打籃球和吃東西”。誰能幫我看看我的代碼有什么問題?xml = '''<item>        <title>Defensive Moves</title>        <link>www.timmy256.wordpress.com</link>        <pubDate></pubDate>        <dc:creator><![CDATA[jross]]></dc:creator>        <guid isPermaLink="false"> www.timmy256.wordpress.com </guid>           <description></description>        <content:encoded><![CDATA[I love playing basketball and eating food.]]></content:encoded>        </item>'''import xml.etree.ElementTree as ETtree = ET.parse(xml)root = tree.getroot()data = root.iter("content:encoded").text
查看完整描述

1 回答

?
素胚勾勒不出你

TA貢獻1827條經驗 獲得超9個贊

另一種方法。


from simplified_scrapy import SimplifiedDoc

xml = '''<item>

        <title>Defensive Moves</title>

        <link>www.timmy256.wordpress.com</link>

        <pubDate></pubDate>

        <dc:creator><![CDATA[jross]]></dc:creator>

        <guid isPermaLink="false"> www.timmy256.wordpress.com </guid>   

        <description></description>

        <content:encoded><![CDATA[I love playing basketball and eating food.]]></content:encoded>

        </item>'''

doc = SimplifiedDoc(xml)

print(doc.select('item>content:encoded>html()')[9:-3])

結果:


I love playing basketball and eating food.

這里有更多例子:https ://github.com/yiyedata/simplified-scrapy-demo/tree/master/doc_examples


查看完整回答
反對 回復 2023-02-12
  • 1 回答
  • 0 關注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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