summaryrefslogtreecommitdiff
path: root/bs4/diagnose.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2015-06-27 11:13:40 -0400
committerLeonard Richardson <leonardr@segfault.org>2015-06-27 11:13:40 -0400
commit3f1c4950a6e1d3b1e8052a4e2168ce5caf89136e (patch)
tree03654910e0d2935576eabc50eda94fd3651bf865 /bs4/diagnose.py
parentfeffc5a1146e2520c90682bc2c33f5fa7d3943f0 (diff)
Added another layer of security to catch cases where lxml and html5lib are not installed.
Diffstat (limited to 'bs4/diagnose.py')
-rw-r--r--bs4/diagnose.py17
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()