diff options
author | Leonard Richardson <leonardr@segfault.org> | 2017-05-06 12:25:28 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2017-05-06 12:25:28 -0400 |
commit | 2874552990cf9668d721808d3dbd1cd80a98c614 (patch) | |
tree | 6f3d36b6891aeb47d04aa74ce0a084b50b196795 | |
parent | 9570003d54c37882aa572744595230d785f33f84 (diff) |
Implement ResultSet.__getattr__ to give a helpful message in a common error scenario.
-rw-r--r-- | bs4/element.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/bs4/element.py b/bs4/element.py index b100d18..9284d11 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -1753,3 +1753,8 @@ class ResultSet(list): def __init__(self, source, result=()): super(ResultSet, self).__init__(result) self.source = source + + def __getattr__(self, key): + raise AttributeError( + "ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key + ) |