HTML alignment using Python

1

I need to align an HTML code , in some parts it comes totally "messy", example:

<li><a href="dsadas">dsadaads</a></li><li><a href="dsadas">dsadaads</a></li><li><a href="dsadas">dsadaads</a></li>

The html comes in just one line, and I want it to be organized like this:

<li><a href="dsadas">dsadaads</a></li>
<li><a href="dsadas">dsadaads</a></li>
<li><a href="dsadas">dsadaads</a></li>

An example would be site , it organizes everything. Now the question is: How can I align the entire site using PYTHON 2.7 . I noticed that there is a library on jsbeautifier site.

I downloaded it and tried to use it, but I did not understand the operation very well.

My code downloads the HTML from my site, which has a long list. Then the file comes as .HTML

JSBEAUTIFER

datafile = file('meusitehtml.html')
import jsbeautifier
res = jsbeautifier.beautify(datafile)
res = jsbeautifier.beautify_file('some_file.js')

I do not quite understand how I can use jsbeautifier .

- > I need an example of how I can use jsbeautifier ?

    
asked by anonymous 18.12.2017 / 16:54

1 answer

0

This is simple to do using the lxml library.

link

Here is an example code:

from lxml import etree, html
documento = html.fromstring('<li><a href="dsadas">dsadaads</a></li><li><a href="dsadas">dsadaads</a></li><li><a href="dsadas">dsadaads</a></li>')
html_formatado = etree.tostring(documento, pretty_print=True).decode('utf8')
print(html_formatado)
    
18.12.2017 / 20:02