diff options
author | Leonard Richardson <leonardr@segfault.org> | 2018-07-18 22:22:19 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2018-07-18 22:22:19 -0400 |
commit | d055e7ab92a65e641f19989f0d92a0fdcc4fdc4c (patch) | |
tree | ac78c0eb01e7793a8557a8b448022745b90232e2 /bs4/element.py | |
parent | 68b55626839a8a0ea9e750fff546e201d144f96c (diff) |
Fixed a bug where find_all() was not working when asked to find a
tag with a namespaced name in an XML document that was parsed as
HTML. [bug=1723783]
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/bs4/element.py b/bs4/element.py index 911b9bc..f010833 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -589,14 +589,21 @@ class PageElement(object): elif isinstance(name, basestring): # Optimization to find all tags with a given name. if name.count(':') == 1: - # This is a name with a prefix. - prefix, name = name.split(':', 1) + # This is a name with a prefix. If this is a namespace-aware document, + # we need to match the local name against tag.name. If not, + # we need to match the fully-qualified name against tag.name. + prefix, local_name = name.split(':', 1) else: prefix = None + local_name = name result = (element for element in generator if isinstance(element, Tag) - and element.name == name - and (prefix is None or element.prefix == prefix) + and ( + element.name == name + ) or ( + element.name == local_name + and (prefix is None or element.prefix == prefix) + ) ) return ResultSet(strainer, result) results = ResultSet(strainer) |