How to build a HTML object in python3?

Viewed 28

It used to be easy to build an HTML instance. In python 2:

import html
obj = html.HTML('html')

But in python3, there is no attribute as "HTML" under "html" module. And I am working on an specific environment and not allowed to install packages there. I wonder if there is anyway to build an HTML object in python3 so that I can use "obj.head","obj.div","obj.p" and other functions. Thanks.

1 Answers

You can create an "html object" via an external python libray. Domonic

Create HTML with python 3 using a standard DOM API. Includes a python port of JavaScript for interoperability and tons of other cool features. A fast prototyping library.

In example you can do something like this:

from domonic.html import *
from domonic import domonic

x = html(body(h1('Hello, World!')))
mydom = domonic.parseString(x)

# Do something with parsed dom here.

Documentation Here: Domonic Docs

Related