diff options
author | Leonard Richardson <leonardr@segfault.org> | 2015-06-27 11:13:40 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2015-06-27 11:13:40 -0400 |
commit | efc7b53c69117e51b24f406cd6742f65b6a7a62b (patch) | |
tree | 3e45690fe0b47be9d5219a3049cd346a5cfd5f0c | |
parent | 017e4526af39ab75286ebfd2d64db25da116f27b (diff) | |
download | beautifulsoup4-efc7b53c69117e51b24f406cd6742f65b6a7a62b.tar.gz |
Added another layer of security to catch cases where lxml and html5lib are not installed.
-rw-r--r-- | bs4/diagnose.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/bs4/diagnose.py b/bs4/diagnose.py index 4d0b00a..1b71983 100644 --- a/bs4/diagnose.py +++ b/bs4/diagnose.py @@ -33,12 +33,21 @@ def diagnose(data): if 'lxml' in basic_parsers: basic_parsers.append(["lxml", "xml"]) - from lxml import etree - print "Found lxml version %s" % ".".join(map(str,etree.LXML_VERSION)) + try: + from lxml import etree + print "Found lxml version %s" % ".".join(map(str,etree.LXML_VERSION)) + except ImportError, e: + print ( + "lxml is not installed or couldn't be imported.") + if 'html5lib' in basic_parsers: - import html5lib - print "Found html5lib version %s" % html5lib.__version__ + try: + import html5lib + print "Found html5lib version %s" % html5lib.__version__ + except ImportError, e: + print ( + "html5lib is not installed or couldn't be imported.") if hasattr(data, 'read'): data = data.read() |