August 2018
Intermediate to advanced
366 pages
10h 14m
English
There is one trick that I frequently apply when using this recipe. It makes it a bit harder to understand what's going on, on the Python side, and that's the reason why I avoided doing it while explaining the recipe itself, but it makes the HTML/XML structure even more readable by getting rid of most Python noise.
If you assign the XMLDocumentBuilder.tag and XMLDocumentBuilder.text methods to some short names, you can nearly disappear the fact that you are calling Python functions and make the XML structure more relevant:
doc = XMLDocument('html', mode='html') with doc as builder: _ = builder.tag _t = builder.text with _('head'): with _('title'): _t('This is the title') with _('body'): with _('div', id='main-div'): with _('h1'): ...