Preventing BeautifulSoup from converting my XML ta

2020-07-09 02:44发布

I am using BeautifulStoneSoup to parse an XML document and change some attributes. I noticed that it automatically converts all XML tags to lowercase. For example, my source file has <DocData> elements, which BeautifulSoup converts to <docdata>. This appears to be causing problems since the program I am feeding my modified XML document to does not seem to accept the lowercase versions. Is there a way to prevent this behavior in BeautifulSoup?

2条回答
家丑人穷心不美
2楼-- · 2020-07-09 02:56

No, that's not a built-in option. The source is pretty straightforward, though. It looks like you want to change the value of encodedName in Tag.__str__.

查看更多
迷人小祖宗
3楼-- · 2020-07-09 03:02
  • Simple Answer
    • change (default html.parser) to xml parser
      • code: soup = BeautifulSoup(yourXmlStr, 'xml')
  • Detailed Explanation
查看更多
登录 后发表回答