Index > Scribe > New SearchHtml scripting function | |
---|---|
Author/Date | New SearchHtml scripting function |
fret 05/03/2022 7:53pm | Historically Scribe's HTML parser is not accessible from the scripting language. So I'm working on adding some basic functionality. In the context of being able to scan a HTML email for some part of the document. To that end there is a new function called 'SearchHtml' that allows script authors to find stuff in the HTML. The function is available on both mail objects and the application object, albeit with slightly different arguments:
Mail.SearchHtml(SearchExpression, ResultExpression); App.SearchHtml(Html, SearchExpression, ResultExpression); The app object needs the HTML argument as well. So what do the SearchExpression and ResultExpression do? They are scripting engine expressions. The variables available in those expressions are: 'element' = the elements name. E.g. "a", "body", "div" etc. 'content' = the texture content following the element. 'attr[name]' = the value of attribute 'name'. As an example this code would search the HTML for anchor elements with certain text inside and then return the href: Results = Mail.SearchHtml("element==\"a\" && " + "(" + " content.lower().find(\"unsub\") >= 0 || " + " content.lower().find(\"opt-out\") >= 0 || " + " content.lower().find(\"stop future communications\") >= 0" + ")", "attr[\"href\"]"); As you can see I'm looking for the unsubscribe link in the email. The result variable contains a list of anchor hrefs. Short of exposing the entire HTML element tree to the scripting API, which seems a little too much work right now, this fills the need to inspect stuff inside the HTML with some level of control. If you have other use cases that this doesn't cover. Feel free to discuss below. |
Reply | |