aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbashonly <88596187+bashonly@users.noreply.github.com>2024-10-29 23:24:17 +0000
committerGitHub <noreply@github.com>2024-10-29 23:24:17 +0000
commitf93c16395cea1fe9ffc3c594d3e019c3b214544c (patch)
tree67247c5e9face6b3292025f4a23799b1e0b132e0
parentf101e5d34c97c608156ad5396714c2a2edca966a (diff)
[utils] Fix `find_element` by class (#11402)
Fix d710a6ca7c622705c0c8c8a3615916f531137d5d Authored by: bashonly
-rw-r--r--yt_dlp/utils/traversal.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/yt_dlp/utils/traversal.py b/yt_dlp/utils/traversal.py
index df3ff406f..0eef817ea 100644
--- a/yt_dlp/utils/traversal.py
+++ b/yt_dlp/utils/traversal.py
@@ -391,14 +391,13 @@ def find_element(*, tag: str, html=False): ...
def find_element(*, tag=None, id=None, cls=None, attr=None, value=None, html=False):
# deliberately using `id=` and `cls=` for ease of readability
assert tag or id or cls or (attr and value), 'One of tag, id, cls or (attr AND value) is required'
- if not tag:
- tag = r'[\w:.-]+'
+ ANY_TAG = r'[\w:.-]+'
if attr and value:
assert not cls, 'Cannot match both attr and cls'
assert not id, 'Cannot match both attr and id'
func = get_element_html_by_attribute if html else get_element_by_attribute
- return functools.partial(func, attr, value, tag=tag)
+ return functools.partial(func, attr, value, tag=tag or ANY_TAG)
elif cls:
assert not id, 'Cannot match both cls and id'
@@ -408,7 +407,7 @@ def find_element(*, tag=None, id=None, cls=None, attr=None, value=None, html=Fal
elif id:
func = get_element_html_by_id if html else get_element_by_id
- return functools.partial(func, id, tag=tag)
+ return functools.partial(func, id, tag=tag or ANY_TAG)
index = int(bool(html))
return lambda html: get_element_text_and_html_by_tag(tag, html)[index]