Parse all item elements with children from RSS feed with beautifulsoup

房东的猫 提交于 2019-12-02 02:53:47

Using BeautifulStoup 4:

import bs4 as bs
doc = bs.BeautifulSoup(xml, 'xml')
for item in doc.findAll('item'):
    for elt in item:
        if isinstance(elt, BeautifulSoup.Tag):
            print(elt)

And here's how you could do the same thing with lxml:

import lxml.etree as ET
doc = ET.fromstring(xml)
for item in doc.xpath('//item'):
    for elt in item.xpath('descendant::*'):
        print(ET.tostring(elt))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!