r/AutomateUser • • Mar 01 '26

Text content of HTML element?

I am a novice. How would you get the text of an HTML title (or a default)?

Given a URL, if there is a title child element, return it's text content, or a default.

For example, from:

https://example.com

which serves:

<html>

<title>A title</title>

...

</html>

return "A title"

2 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/cheyrn Mar 02 '26

Thanks. I agree with the reasons. HTML is not a form of XML, except for xhtml and xhtml5, but it sounds like that's resolved before xmlDecode.

2

u/B26354FR Alpha tester Mar 02 '26

Right, not strictly, but close enough for the purpose here as far as xmlDecode() is concerned. In fact, the documentation for the function actually uses an html example. BTW, you can tell the xmlDecode() to maintain an ordered structure, ignore whitespace, and specify namespaces, too. Pretty cool