lxml/lxml — pull request #140 by jab (2014-09-02 13:55:18+00:00)
Title: lxml.html.document_fromstring ensure_head option

When using lxml.html.document_fromstring to process html outside your control,
you can't be sure it will have a head element. Allowing document_fromstring to
accept an ensure_head option saves you from having to write code like:

doc = document_fromstring(html)
try:
doc.head
except IndexError:
from lxml.html import builder
doc.insert(0, builder.HEAD())
# now we can safely reference doc.head

and instead just write:

doc = document_fromstring(html, ensure_head=True)