SEARCH

(Copy URL in PhpBB Forum Format - Info)

From iMacros

Jump to: navigation, search

The SEARCH commands works with page source, instead of looking at the web page object model (DOM) that the TAG command uses. Thus SEARCH also "sees" e. g. comments in the page source code.

Contents

Syntax iMacros Browser IE Plug-in Firefox

SEARCH SOURCE=(TXT|REGEXP) IGNORE_CASE=YES EXTRACT=$1

Notes

  1. The default is IGNORE_CASE=NO
  2. Extracted information is always of type text, as the SEARCH command works on the page source code. $1 refers to the Regular Expressions syntax. So the use of EXTRACT requires the use of the REGEX attribute.
  3. The REGEXP attribute works with standard Regular Expressions (often called regex or regexp).
  4. Global, iterative matching is currently not supported, so only the first match on the page can be found and extracted.
  5. iMacros Browser and iMacros for IE use the .NET regexp engine and since the backslash is an escape sequence by itself, its occurrence has to be escaped as well. For example: to specify \S in your regular expression, you should use \\S.
  6. iMacros for Firefox uses the Javascript regexp engine, which does not support lookbehind notation: "(?<=ABC)".

Examples

Test macro: This macro checks for the presence of the Google Analytics script on our website and then extracts the ID of it.

 URL GOTO=http://iopus.com/
 'Check for Script
 SEARCH SOURCE=TXT:"_gat._getTracker(\"UA-336765-1\")"
 'Check for Script, ignore case
 SEARCH SOURCE=TXT:"_gettracker" IGNORE_CASE=YES
 'Use regular expression to extract data
 SEARCH SOURCE=REGEXP:"_get[Tt]racker\\(([^)]+)\\)" EXTRACT="Tracker is $1"
 'Display extracted data
 PROMPT {{!EXTRACT}}


Note: REGEXP:"_get[Tt]racker\\(([^)]+)\\)" means:

  • find the word _get[Tt]racker, with T or t
  • \\( - opening brace
  • [^)]+ followed by anything except closing brace [^)] repeated one or more times +
  • \\) and ending with closing brace
  • => anything but not a closing brace is surrounded by capturing braces - ()
  • => it extracts the argument of the gettracker command, that is the text between (...)
  • The result is saved in $1, which is then assigned to the !EXTRACT variable

Another example: Search for a script. Escape " with \"

 SEARCH SOURCE=TXT:"<script src=\"/js/datevalidator.js\""

Related Forum Posts

See Also

Personal tools
Home
Toolbox

Website Monitoring