extract-and-fill.vbs
From iMacros
This example script extracts information from one website and uses this to fill a form on another.
Macros used:
- Wsh-Extract-Rate
- Wsh-Extract-And-Fill-Part2
Visual Basic Script:
'Note: EXTRACT requires Internet Explorer 6.0 or better to be installed
Msgbox ("This example shows how to use a data EXTRACTION and then fill the extracted data into a new form. It uses two macros for this purpose.")
dim ExchangeRate
set iim1= CreateObject ("imacros")
iret = iim1.iimInit ()
'--- Extraction starts ---
iret = iim1.iimDisplay("Extract Data")
iplay = iim1.iimPlay("wsh-extract-rate")
data = iim1.iimGetLastExtract()
errortext = iim1.iimGetLastError()
'Check for errors:
If iplay = 1 and len (data) = 0 Then
MsgBox "Done, but no data extracted. This case should not happen unless there is no EXTRACT command in the macro."
WScript.Quit(0)
End If
If iplay < 0 Then
s = "The following error occurred: " + vbCrLf + vbCrLf + data
MsgBox s
WScript.Quit(0)
End If
ExchangeRate= Split(data, "[EXTRACT]")
'--- Extraction done ---
'Prepare the extracted data for submission
'For example, you can do calculations on the values.
'In this example, we substract 0.111 from the extracted value
'(uncomment the following lines to enable substraction)
's = ExchangeRate(0)
'Msgbox "Substract 0.111 from " + s
's = s - 0.01
'ExchangeRate(0) = cstr (s)
'Or one could also add IF/THEN statements here to make descision based
'on extracted values.
s = "Hello Jim," +vbCrLf + vbCrLf
s = s + "Did you know? One US$ costs " + ExchangeRate(0) + " EURO or " + ExchangeRate(1) + " British Pounds (GBP)."
'--- Submission starts ---
iret = iim1.iimDisplay("Submit extracted data")
iret = iim1.iimSet ("-var_currency", s)
iplay = iim1.iimPlay("wsh-extract-and-fill-part2")
If iplay < 0 Then
s = "The following error occurred: " + vbCrLf + vbCrLf + iim1.iimGetLastError()
MsgBox s
End If
iret = iim1.iimExit
WScript.Quit(0)
Macro code for Wsh-Extract-Rate:
VERSION BUILD=300625 TAB T=1 TAB CLOSEALLOTHERS URL GOTO=http://www.iopus.com/imacros/demo/v5/extract.htm 'Get the values EXTRACT POS=28 TYPE=TXT ATTR=<TD<SP>class=bdytxt>* EXTRACT POS=29 TYPE=TXT ATTR=<TD<SP>class=bdytxt>*
Macro code for Wsh-Extract-And-Fill-Part2:
VERSION BUILD=320024 'This macro is the second macro used in the 'extract-and-fill.vbs example TAB T=1 TAB CLOSEALLOTHERS URL GOTO=http://www.iopus.com/imacros/demo/v5/f1/form.asp TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:TestForm ATTR=NAME:Name CONTENT=Tom<SP>Tester TAG POS=1 TYPE=TEXTAREA FORM=NAME:TestForm ATTR=NAME:Remarks CONTENT={{currency}} TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:TestForm ATTR=NAME:SendButton&&VALUE:Click<SP>to<SP>order<SP>now WAIT SECONDS=3
