Search code examples
javascriptimacros

String Formatting | JavaScript | iMacros


I am trying to extract the metadata description and keywords for a webpage using iMacros.

The source code looks like this:

<meta name="description" content="test test test">
<meta name="keywords" content="abc abc abc">

The iMacros code looks like this:

TAG POS=1 TYPE=META ATTR=NAME:"description" EXTRACT=HTM
TAG POS=1 TYPE=META ATTR=NAME:"keywords" EXTRACT=HTM

The Extract output from iMacros is :

<meta name="description" content="test test test">

Now, I just need the content part as my output :

test test test

I came to know that we can use JavaScript in iMacros using **EVAL command. So, can one please help in formatting the string to desired output ?**


Solution

  • Yes, you need to use the EVAL command. For example in this way:

    SET !EXTRACT_TEST_POPUP NO
    TAG POS=1 TYPE=META ATTR=NAME:"description" EXTRACT=HTM
    SET description EVAL("'{{!EXTRACT}}'.match(/content="(.+?)"/)[1];")
    PROMPT {{description}}