diff options
author | Leonard Richardson <leonardr@segfault.org> | 2018-12-24 10:17:54 -0500 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2018-12-24 10:17:54 -0500 |
commit | 3c3b6467d8c96042d1292c14a9b6d4518a298b6b (patch) | |
tree | 654821887077da931e464ab34ebe3e8fbb7b4785 /bs4/element.py | |
parent | 50ded6dbdfeba182233fff86eb98513e09fcde93 (diff) |
Issue a warning and raise a more useful exception if someone tries to call Tag.select() without SoupSieve installed.
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/bs4/element.py b/bs4/element.py index 7734f80..97403c9 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -9,7 +9,14 @@ except ImportError , e: import re import sys import warnings -import soupsieve +try: + import soupsieve +except ImportError, e: + soupsieve = None + warnings.warn( + 'The soupsieve package is not installed. CSS selectors cannot be used.' + ) + from bs4.dammit import EntitySubstitution DEFAULT_OUTPUT_ENCODING = "utf-8" @@ -1347,7 +1354,11 @@ class Tag(PageElement): if limit is None: limit = 0 - + if soupsieve is None: + raise NotImplementedError( + "Cannot execute CSS selectors because the soupsieve package is not installed." + ) + return soupsieve.select(selector, self, namespaces, limit, **kwargs) # Old names for backwards compatibility |