def _build_doc(self):
from lxml.html import parse, fromstring, HTMLParser<EOL>from lxml.etree import XMLSyntaxError<EOL>parser = HTMLParser(recover=True, encoding=self.encoding)<EOL>try:<EOL><INDENT>if _is_url(self.io):<EOL><INDENT>with urlopen(self.io) as f:<EOL><INDENT>r = parse(f, parser=parser)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>r = parse(self.io, parser=parser)<EOL><DEDENT>try:<EOL><INDENT>r = r.getroot()<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>except (UnicodeDecodeError, IOError) as e:<EOL><INDENT>if not _is_url(self.io):<EOL><INDENT>r = fromstring(self.io, parser=parser)<EOL>try:<EOL><INDENT>r = r.getroot()<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise e<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not hasattr(r, '<STR_LIT>'):<EOL><INDENT>raise XMLSyntaxError("<STR_LIT>", <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT><DEDENT>return r<EOL>
Raises
------
ValueError
    * If a URL that lxml cannot parse is passed.

Exception
    * Any other ``Exception`` thrown. For example, trying to parse a
      URL that is syntactically correct on a machine with no internet
      connection will fail.

See Also
--------
pandas.io.html._HtmlFrameParser._build_doc