I was wondering if it is possible to make sure that prettify does not create new lines for certain tags.
I would like to make the span and a tags not break, for example:
doc="""<div><div><span>a</span><span>b</span> <a>link</a></div><a>link1</a><a>link2</a></div>""" from bs4 import BeautifulSoup as BS soup = BS(doc) print soup.prettify()
below is what I want to print:
<div> <div> <span>a</span><span>b</span> <a>link</a> </div> <a>link1</a><a>link2</a> </div>
But this is what will actually be printed:
<div> <div> <span> a </span> <span> b </span> <a> link </a> </div> <a> link1 </a> <a> link2 </a> </div>
Placing inline tag styles on new lines like this will actually add space between them, slightly changing the way the actual page looks. I will connect you with two jsfiddles displaying the difference:
If you're wondering why this is important for BeautifulSoup, this is because I am writing a web page debugger, and the prettify function will be very useful (along with other things in bs4). But if I embellish the document, I risk changing some things.
So, is there a way to configure the prettify function prettify that I can set it so as not to break specific tags?
python html beautifulsoup
Ryan saxe
source share