The renewal maintenance has officially ended for Progress iMacros effective November 30, 2023.
This Wiki site will also no longer be moderated from the Progress side.
Thank you again for your business and support.
Sincerely, The Progress Team
Difference between revisions of "SEARCH"
Jump to navigation
Jump to search
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
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. | 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. | ||
− | === Syntax [[Image:IMacros-icon.png|iMacros Browser]] [[Image:Ie-icon.png|IE Plug-in]] [[Image:Ff-icon.png|Firefox]]=== | + | === Syntax [[Image:IMacros-icon.png|iMacros Browser]] [[Image:Ie-icon.png|IE Plug-in]] [[Image:Ff-icon.png|Firefox]] [[Image:Cr-icon.png|Chrome]]=== |
SEARCH SOURCE=(TXT|REGEXP) IGNORE_CASE=YES EXTRACT=$1 | SEARCH SOURCE=(TXT|REGEXP) IGNORE_CASE=YES EXTRACT=$1 | ||
− | Notes | + | === Notes === |
− | + | # The default is IGNORE_CASE=NO | |
− | + | # 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. | |
− | + | # The REGEXP attribute works with standard [[Regular Expressions]] (often called regex or regexp). | |
− | + | # Global, iterative matching is currently not supported, so only the first match on the page can be found and extracted. | |
− | + | # iMacros Browser and iMacros for IE use the [http://www.regular-expressions.info/dotnet.html .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. | |
+ | # iMacros for Firefox uses the Javascript regexp engine, which does not support lookbehind notation: "(?<=ABC)". | ||
=== Examples === | === Examples === | ||
Test macro: This macro checks for the presence of the Google Analytics script on our website and then extracts the ID of it. | 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://demo.imacros.net | |
− | + | 'Check for tracker | |
− | + | SEARCH SOURCE=TXT:"'UA-336765-10'" | |
− | + | 'Check for tracker, ignore case | |
− | + | SEARCH SOURCE=TXT:"'ua-336765-10'" IGNORE_CASE=YES | |
− | + | 'Use regular expression to extract data | |
− | + | SEARCH SOURCE=REGEXP:"(UA-[0-9\-]+)" EXTRACT="Tracker is $1" | |
− | + | 'Display extracted data | |
− | + | PROMPT <nowiki>{{!EXTRACT}}</nowiki> | |
− | + | Note: REGEXP:"ga\\('create', '([^']+)', 'imacros.net'\\)" means: | |
− | Note: REGEXP:" | + | * find the word ga followed by an opening brace \\( and the first parameter value 'create' followed by a comma and the start of the next parameter |
− | * find the word | + | * ( starts a capturing group |
− | * | + | * [')]+ followed by anything except a single quote [^'] repeated one or more times + |
− | * [ | + | * ) ends the capturing group |
− | * | + | * ' and ending with a single quote |
− | + | * => '''it extracts''' the second argument of the ga command ('''the text between the '...''''), which is our tracker id | |
− | * => '''it extracts''' the argument of the | ||
* The result is saved in $1, which is then assigned to the [[!EXTRACT]] variable | * The result is saved in $1, which is then assigned to the [[!EXTRACT]] variable | ||
Line 40: | Line 40: | ||
=== Related Forum Posts === | === Related Forum Posts === | ||
− | * [ | + | * [https://forum.imacros.net/viewtopic.php?f=7&t=11447&p=34605#p34605 iMacros for Firefox does not support lookbehind notation] |
− | * [ | + | * [https://forum.imacros.net/viewtopic.php?f=7&t=11516 No global, iterative matching using SEARCH] |
+ | * [https://forum.imacros.net/viewtopic.php?f=7&t=12260 REGEX difference between Firefox and IE] | ||
+ | * [https://forum.imacros.net/viewtopic.php?f=7&t=11200 Most Efficient Way To Extract Source Code] | ||
== See Also == | == See Also == | ||
*Detect script errors with [[ONERRORDIALOG]] BUTTON=NO CONTINUE=NO | *Detect script errors with [[ONERRORDIALOG]] BUTTON=NO CONTINUE=NO |
Revision as of 11:19, 19 December 2018
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.
Syntax
SEARCH SOURCE=(TXT|REGEXP) IGNORE_CASE=YES EXTRACT=$1
Notes
- The default is IGNORE_CASE=NO
- 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.
- The REGEXP attribute works with standard Regular Expressions (often called regex or regexp).
- Global, iterative matching is currently not supported, so only the first match on the page can be found and extracted.
- 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.
- 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://demo.imacros.net 'Check for tracker SEARCH SOURCE=TXT:"'UA-336765-10'" 'Check for tracker, ignore case SEARCH SOURCE=TXT:"'ua-336765-10'" IGNORE_CASE=YES 'Use regular expression to extract data SEARCH SOURCE=REGEXP:"(UA-[0-9\-]+)" EXTRACT="Tracker is $1" 'Display extracted data PROMPT {{!EXTRACT}}
Note: REGEXP:"ga\\('create', '([^']+)', 'imacros.net'\\)" means:
- find the word ga followed by an opening brace \\( and the first parameter value 'create' followed by a comma and the start of the next parameter
- ( starts a capturing group
- [')]+ followed by anything except a single quote [^'] repeated one or more times +
- ) ends the capturing group
- ' and ending with a single quote
- => it extracts the second argument of the ga command (the text between the '...'), which is our tracker id
- 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
- iMacros for Firefox does not support lookbehind notation
- No global, iterative matching using SEARCH
- REGEX difference between Firefox and IE
- Most Efficient Way To Extract Source Code
See Also
- Detect script errors with ONERRORDIALOG BUTTON=NO CONTINUE=NO