Could not find XML element's text %s
Package:
youtube-dl
99648

Exception Class:
ExtractorError
Raise code
if n is None or n == default:
return n
if n.text is None:
if default is not NO_DEFAULT:
return default
elif fatal:
name = xpath if name is None else name
raise ExtractorError('Could not find XML element\'s text %s' % name)
else:
return None
return n.text
def xpath_attr(node, xpath, key, name=None, fatal=False, default=NO_DEFAULT):
n = find_xpath_attr(node, xpath, key)
🙏 Scream for help to Ukraine
Today, 14th August 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/ytdl-org/youtube-dl/blob/dfbbe2902fc67f0f93ee47a8077c148055c67a9b/youtube_dl/utils.py#L1919Ways to fix
Error code:
from youtube_dl.compat import compat_etree_fromstring
from youtube_dl.utils import xpath_text
testxml = '''<root>
<div>
</div>
</root>'''
doc = compat_etree_fromstring(testxml)
xpath_text(doc, 'div/p',fatal=True)
Explanation:
The error is raised when using xpath_text. It extracts text from a given XPath based on given tags. In the above example, we will get an error because we don't have a <p>
tag to parse.
To avoid an error,
1) change the fatal parameter to True
2) pass exact tags to parse
Fix code:
from youtube_dl.compat import compat_etree_fromstring from youtube_dl.utils import xpath_text testxml = '''<root> <div> <p>Foo</p> </div> </root>''' doc = compat_etree_fromstring(testxml) xpath_text(doc, 'div/p',fatal=True)
Add a possible fix
Please authorize to post fix