def parse_lxml(content):

    if not isinstance(content, StringIO):
        if not isinstance(content, str) and not isinstance(content,
                                                           unicode):
            raise Exception("input content must be a str or StringIO"
                            "instead of " + str(type(content)))
        content = StringIO(content)

    lxml_tree = lxml.etree.parse(content, lxml_parser)
    return lxml_tree
from gist: https://gist.github.com/kanzure/5385691
dataset/ETHPy150Open numb3r3/crawler-python/crawler/core/base.py/parse_lxml