Skip to content

Commit

Permalink
[utils] Fix find_element by class (#11402)
Browse files Browse the repository at this point in the history
Fix d710a6c

Authored by: bashonly
  • Loading branch information
bashonly authored Oct 29, 2024
1 parent f101e5d commit f93c163
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions yt_dlp/utils/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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]
Expand Down

0 comments on commit f93c163

Please sign in to comment.