Shankar Guru
Shankar Guru

Reputation: 1161

Remove outer tags from Beautiful soup output

I have an xml which is generated after below beautifulsoup statement. It generates an XML which contains html and body tags. I want to remove both html and body tags from output. Can I please know how I can achieve the same ?

Code:

soup = bs(''.join(output), "lxml")
print("soup output : {}".format(soup.html))

output:

<html>
<body>
...
</body>
</html>

Upvotes: 1

Views: 230

Answers (1)

Sheng Zhuang
Sheng Zhuang

Reputation: 697

try this:

body = soup.find("body")
innerbody = body.decode_contents()

Upvotes: 3

Related Questions