with open('page.html') as f:
    doc = parse(f.read(), treebuilder='lxml', namespaceHTMLElements=False)
html = doc.getroot()
body = html.xpath('//body')[0]

def sanitize(element):
    """Retrieve all the text contained in an element as a single line of
    text. This must be executed only on blocks that have only inlines
    as children
    """
out = ' '.join(element.itertext()).replace('\n', ' ')
out = ' '.join(out.split())
Parsing HTML into sentences - how to handle tables/lists/headings/etc?