Related example scripts: Extract-and-fill.vbs, Extract-2-file.vbs, Get-Exchange-Rate.vbs
All extracted data can be sent to your code via the Scripting Interface. This gives you all the power of any programming language you choose to process the extracted information further or simply save it to a file.
Use the iimGetLastExtract command to return the extracted text if you used any EXTRACT commands within the macro.
The extracted text is returned as a string. Extracted information resulting from different EXTRACT commands are separated by [EXTRACT], e.g.
Text to be extracted[EXTRACT]Salary: 33,000.00 per year[EXTRACT]...
Remember: Using the SAVEAS TYPE=EXTRACT command will reset the contents of the !EXTRACT variable. Thus, using this command in a macro whose extraction result you wish to obtain via the Scripting Interface will result in an empty string in your application!
If you extract a complete table, the data from different columns is separated by #NEXT# and each table row ends with #NEWLINE#. You can easily use the separation tags to split the complete dataset. In Visual Basic Script, this would for example look something like s = Replace(s, "#NEWLINE#", """" + vbCrLf + """")
s = Replace(s, "#NEXT#", """"+ "," + """")
Example 1 - Split the returned string
The returned string is split to separate the results from different EXTRACT commands.
Dim data as String
Dim s as String
Dim ExchangeRate
iplay = iim1.iimPlay("wsh-extract")
If iplay = 1 Then
data = iim1.iimGetLastExtract()
ExchangeRate= Split(data, "[EXTRACT]")
s = "One US$ costs " + ExchangeRate(0) + " EURO or " + ExchangeRate(1) + " British Pounds (GBP)"
MsgBox s
End If
Example 2 - Keyword search We want to find out if the word iopus exists on a web page. If yes, print the page. To make this example work, create the following macro and save it under the filename mysearch.iim in your Macros directory: VERSION BUILD=3301125
'The keyword *is* the data extraction anchor!
EXTRACT POS=1 TYPE=TXT ATTR=*iopus*
To print the web page, create the following macro and save it under the filename print_this.iim in your Macros directory: VERSION BUILD=3301125
PRINT
Use the following Windows Script to control the macros:
set iim1= CreateObject ("InternetMacros.iim")
iret = iim1.iimInit()
iplay = iim1.iimPlay("mysearch")
extracted_text = iim1.iimGetLastExtract()
'test if keyword appeared on website.
If iplay = 1 Then
if instr (extracted_text, "#EANF#") > 0 then
MsgBox ("Sorry, keyword not found")
else
iplay = iim1.iimPlay("print_this")
End If
End if
If iplay < 0 Then
MsgBox "Error!"
End If
Note: You can also write directly to any Windows database. Please see the extract-2-database.vbs script for some example code. The script writes all results directly to a Microsoft Access database.
More Examples:
iMacros comes with several example scripts that demonstrate the EXTRACT command:
·
extract-2-file.vbs
·
extract-and-fill.vbs
·
get-exchange-rate.vbs
The scripts are found in the Examples\Windows Scripting Host directory of your iMacros installation. More example scripts and test pages are available at http://www.iopus.com/imacros/demo