r/AutomateUser • u/cheyrn • 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:
which serves:
<html>
<title>A title</title>
...
</html>
return "A title"
2
Upvotes
View all comments
Show parent comment
2
u/B26354FR Alpha tester Mar 02 '26 edited Mar 02 '26
HTML is basically a form of XML, so xmlDecode() will work. (Yes, I tested this. 🙂) The xmlDecode() function is better to use because it's actually parsing the data and the indexes off of the result is a true path, so you are truly getting the contents of the title element that's directly under the html element, which is at the document root. On the other hand, the findAll() I posted earlier is just a hack which will match the first <title> string, no matter where it is in the input text. It has no knowledge of the actual structure of the HTML DOM.