https://github.com/byteface/domonic/
A DOM for making HTML with python 3! (and more)
Install
python3 -m pip install domonic
# python3 -m pip install domonic --upgrade
Creating HTML with Python 3
from domonic.html import *
print(html(body(h1('Hello, World!'))))
# <html><body><h1>Hello, World!</h1></body></html>
or to pretty format and insert the doctype, use an f-string:
mydom = html(body(h1('Hello, World!'), a("somelink", _href="somepage.html")))
print(f"{mydom}")
<!DOCTYPE html>
<html>
<body>
<h1>Hello, World!</h1>
<a href="somepage.html">somelink</a>
</body>
</html>
parsing html
Basic useage...
from domonic import domonic
mydom = domonic.parseString('<somehtml...')
To quickly parse a webapge try the window module...
from domonic.window import window
window.location = "http://www.google.com"
print(window.document.title)
Also try the xpath or css selectors on command line...
domonic -x https://google.com '//a[@class]' | uniq | sort
domonic -q https://google.com 'a' | uniq | sort
Top comments (0)