您的任务,就像大多数重要的抓取问题一样,可以使用 javascript 来组织您的 imacros 代码更容易地解决
看看这个例子。我不使用富国银行所以我无法测试实际下载但基本骨架在那里
run()
function run() {
// loginResult is null on success
var loginError = performLogin()
if (loginError) {
alert(JSON.stringify(loginError, null, ' '))
throw new Error(JSON.stringify(loginError))
}
// loginResult is null on success
var extractError = extractStatement()
if (extractError) {
alert(JSON.stringify(extractError, null, ' '))
throw new Error(JSON.stringify(extractError))
}
iimDisplay('Download completed successfully')
}
/**
* @return null on success, error object on failure
*/
function extractStatement() {
var error,
code,
extract
code = iimPlay('CODE: TAG POS=1 TYPE=A ATTR=TXT:View<SP>online<SP>statements\n'
+ 'TAG POS=1 TYPE=A ATTR=TXT:Statement<SP>* EXTRACT=TXT')
if (code !== 1) {
error = {
message: 'error extracting statement',
error: iimGetLastError(),
errorCode: code
}
}
extract = iimGetLastExtract()
// #EANF# means Extract Anchor Not Found (ie extract failed)
if (extract === '#EANF#') {
error = {
message: 'error extracting statement',
error: 'extract not found'
}
}
// the magic line to replace all slashes
var filename = extract.replace(/\//g, '-')
// add the .pdf extension
filename = filename + '.pdf'
// download with the new filename, the double slashes are needed because
// javascrtip otherwise views a backslash as an escape character
var folderPath = 'D:\\Wells<SP>Fargo\\CREDIT<SP>CARD\\'
var downloadCode = iimPlay('CODE: ONDOWNLOAD FOLDER=' +folderPath + ' FILE=' + filename + '\n'
+ 'TAG POS=1 TYPE=A ATTR=TXT:Statement<SP>* CONTENT=EVENT:SAVETARGETAS\n'
+ 'TAB CLOSE')
if (downloadCode !== 1) {
error = {
message: 'failed to download statement',
error: iimGetLastError(),
errorCode: downloadCode
}
return error
}
// download completed correctly
return null
}
/**
* @return null on success, error object on failure
*/
function performLogin() {
var code = iimPlay('CODE: TAB OPEN\n'
+ 'TAB T=2\n'
+ 'URL GOTO=https://online.wellsfargo.com/login\n'
+ 'TAG POS=1 TYPE=INPUT:TEXT FORM=ID:Signon ATTR=ID:username CONTENT=XXX\n'
+ 'SET !ENCRYPTION TMPKEY\n'
+ 'TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:Signon ATTR=ID:password CONTENT=XXX\n'
+ 'TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:Signon ATTR=NAME:continue&&VALUE:Sign<SP>On\n')
// code will be 1 on success
if (code === 1) {
return null
}
var error = {
message: 'error performing login',
error: iimGetLastError(),
errorCode: code
}
}