selfClosingTags in BeautifulSoup

后端 未结 2 991
Happy的楠姐
Happy的楠姐 2021-01-13 15:57

Using BeautifulSoup to parse my XML

import BeautifulSoup

soup = BeautifulSoup.BeautifulStoneSoup( \"\"\"hello         


        
2条回答
  •  我在风中等你
    2021-01-13 16:34

    I don't have a "why", but this might be of interest to you. If you use BeautifulSoup (no Stone) to parse XML with a self-closing tag, it works. Sort of:

    >>> soup = BeautifulSoup.BeautifulSoup( """hello""" ) # selfClosingTags=['alan'])
    >>> print soup.prettify()
    
    
    
     hello
    
    

    The nesting is right, even if alan is rendered as a start and an end tag.

提交回复
热议问题