Javi DR
Javi DR

Reputation: 165

beautifulsoup - how to convert back from soup to html

I am using beautifulsoup to convert parse and edit an html. This works perfectly, but, when converting the soup object back to html with prettify(formatter="html"), it adds a lot of spaces and newlines that were not in the original html

What can i do to keep the original formatting?

Thanks

Upvotes: 2

Views: 1606

Answers (1)

HedgeHog
HedgeHog

Reputation: 25048

Cause you create BeautifulSoup object from a string a general approach would be to convert it back in this way. To get a more specific answer, please improve question and add details to clarify.

String to BeautifulSoup object:

soup = BeautifulSoup(string)

BeautifulSoup object to string:

str(soup)

Upvotes: 3

Related Questions