1
我保存在一个XML文件中鸣叫:阅读CDATA从XML文件BeautifulSoup
<tweet>
<tweetid>142389495503925248</tweetid>
<user>ccifuentes</user>
<content><![CDATA[Salgo de #VeoTV , que día más largoooooo...]]></content>
<date>2011-12-02T00:47:55</date>
<lang>es</lang>
<sentiments>
<polarity><value>NONE</value><type>AGREEMENT</type></polarity>
</sentiments>
<topics>
<topic>otros</topic>
</topics>
</tweet>
分析这些,我通过
soup = BeautifulSoup(xml, "lxml")
其中XML是原始的XML创建BeautifulSoup实例文件。要访问一个单一的鸣叫我这样做:
tweets = soup.find_all('tweet')
for tw in tweets:
print(tw)
break
这导致
<tweet>
<tweetid>142389495503925248</tweetid>
<user>ccifuentes</user>
<content></content>
<date>2011-12-02T00:47:55</date>
<lang>es</lang>
<sentiments>
<polarity><value>NONE</value><type>AGREEMENT</type></polarity>
</sentiments>
<topics>
<topic>otros</topic>
</topics>
</tweet>
需要注意的是,当我打印的第一鸣叫CDATA部分省略。对我来说这很重要,我该怎么做?
干杯,解析器之间的主要区别是什么? –
@Vladimir Vargas不同的解析器在数据类型的某些部分中的行为不同,在大多数情况下,它们都是相同的。 –
是的,由于时间限制我无法接受它。 –