English 中文(简体)
iMacros:将Javascript with EVAL改为变式案文
原标题:iMacros: Using Javascript with EVAL to replace text in a variable

I m 采用iMacros 下载我Wissam Fargo PDF银行报表,并自动提供链接的名称,如“Statement 04/22/12 (597K)

然而,我可以用卷宗名称(Windows 限制......)lash。 因此,Im试图用dash/strong>取代forward slashes

Here is my iMacro below. I get an error code on the following line:

SET !VAR1 EVAL("var s="{{!EXTRACT}}"; s.replace(///g, "-");") 

我的哈瓦特或我的雷克做了一些工作,我不知道为什么。 我说两种语言都不是强硬的——我试图从其他例子中尽可能地复制,但没有任何成功。 如果你能够提供帮助,那是巨大的。 感谢。

VERSION BUILD=5010424 RECORDER=CR
  SET !ERRORIGNORE YES

TAB OPEN
TAB T=2
URL GOTO=https://online.wellsfargo.com/login
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:Signon ATTR=ID:username CONTENT=XXX
SET !ENCRYPTION TMPKEY
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:Signon ATTR=ID:password CONTENT=XXX
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:Signon ATTR=NAME:continue&&VALUE:Sign<SP>On
TAG POS=1 TYPE=A ATTR=TXT:View<SP>online<SP>statements

SET !EXTRACT_TEST_POPUP NO

TAG POS=1 TYPE=A ATTR=TXT:Statement<SP>* EXTRACT=TXT
SET !VAR1 EVAL("var s="{{!EXTRACT}}"; s.replace(///g, "-");")    <---- THIS IS THE PROBLEMATIC LINE!!!!!!!!!!!!!!
ONDOWNLOAD FOLDER=D:Wells<SP>FargoCREDIT<SP>CARD FILE={{!VAR1}}.pdf
TAG POS=1 TYPE=A ATTR=TXT:Statement<SP>* CONTENT=EVENT:SAVETARGETAS

TAB CLOSE

另外,如果你知道如何将“(597K)与“Reex”移至“javascript”,那么ake就是ic。 (很明显,这一案文对每个不同档案的价值将有所不同,因此它必须是动态的)

问题回答

You missed escaping the quotes in "-", so ended the iMacros string instead of starting a JavaScript string.

您也有可能在<代码>/ regexp上出现问题,因为我怀疑iMacros会吃/,将其带入/,使联合材料与无效字面代码/。 该编码应为<代码>//。

此外,如果是<代码>! EXTRACT 变量包括引文、斜.或新条线,将直接将这些文字纳入 Java本法典,打破《联合材料》的字面字面,并可能执行任意文字。

这些例子说明了在封闭环境中存在许多问题。 可以通过使用替代的“非冲突”字句来避免前两条,并通过使用简单的“条码”取代“条码”。 而是:

SET !VAR1 EVAL(" {{!EXTRACT}} .split( / ).join( - ).split(  ( )[0]") 

but this still leaves the JS injection problem. From a quick look at the manual, it seems iMacros doesn t have any usable string processing functionality, so you wouldn t be able to do a manual JS-string-literal-replace, or indeed just do the /-to- replacement from within iMacros. That would have been the sensible thing to do; creating executable code from strings is almost always a disastrously wrong thing to strenuously avoid.

[除入境外: 从这一角度来看,Imacros的存在使我真正感到不快。 它向你们提供一种完全任意的、无法使用的口述语言,而不是仅仅使用已经存在的 Java本,然后使你去向联合材料,做任何超出可笑的三边的东西......,而没有给你提供工具来安全地在两者之间转让价值观。 哪怕是这一软件? 我感到这种沮丧的是,自4个利比里亚人的黑暗日以来,试图围绕错头语言设计工作。 这只是一件事。 人们利用这种方式?

你的任务,像大多数非致命的报废问题一样,可以更方便地利用javascript组织你的免疫器码。

探讨这个例子。 我不使用水井,所以我可以测试实际下载情况,但基本舱位在那里。

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
 
                 +  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 +  
 
                             +  TAG POS=1 TYPE=A ATTR=TXT:Statement<SP>* CONTENT=EVENT:SAVETARGETAS
 
                            +  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
 
                     +  TAB T=2
 
                     +  URL GOTO=https://online.wellsfargo.com/login
 
                     +  TAG POS=1 TYPE=INPUT:TEXT FORM=ID:Signon ATTR=ID:username CONTENT=XXX
 
                     +  SET !ENCRYPTION TMPKEY
 
                     +  TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:Signon ATTR=ID:password CONTENT=XXX
 
                     +  TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:Signon ATTR=NAME:continue&&VALUE:Sign<SP>On
 )

  // code will be 1 on success
  if (code === 1) {
    return null
  }
  var error = {
    message:  error performing login ,
    error: iimGetLastError(),
    errorCode: code
  }
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.