iMacros EVAL没有提供正确的输出

时间:2013-03-02 18:59:28

标签: javascript macros eval substring imacros

好的,所以我试图从网站上搜集一些信息来尝试解释像11/22 [50%]这样的值。我可以保证该值至少是子字符串大小所需的最小值。到目前为止,代码可以找到数据,提取数据并将其设置为!VAR1。但是出于某种原因,我无法将它放到页面上的输入字段中。它正确切换,它找到输入字段并输入“Extraction Results:”,就是这样。

所以我的输入是11/22 [50%],我只想要11。所以我将字符串从1,2位分割给我11。

根据iMacros维基,我的语法是正确的,宏运行,我只是没有得到预期的输出,我假设因为我的EVAL线。有谁知道为什么?此外,我将非常感谢您的解释。

VERSION BUILD=7601105 RECORDER=FX
TAB T=1
'Go to website
URL GOTO=http://xxxxxxxxxxxxxxxxxxxx

'Set tag to refer to next
TAG POS=1 TYPE=TD ATTR=TXT:Nerve:

'Get the relative position of something that cannot be tagged and extract the cell's info
TAG POS=R1 TYPE=TD ATTR=TXT:* EXTRACT=TXT

'Set VAR1 to Extracted info (For debugging)
SET !VAR1 {{!EXTRACT}}

'Issue must be here, this is trying to run javascript substring on the information harvested.
SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\"; s=s.substring(1,2); s;")

"Extract to null value to be referenced later
SET !EXTRACT NULL

'Test VAR2 by going to another page and posting the info in a textbox.
URL GOTO=http://xxxxxxxxxxxxxxxxxxxx
TAG POS=1 TYPE=INPUT ATTR=NAME:search[id] CONTENT=Extraction<SP>results:{{!VAR2}}

1 个答案:

答案 0 :(得分:1)

尝试使用

SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\"; s=s.split(\"/\")[0];s;")

String.split()函数将字符串拆分为一个数组,当它找到你作为参数提供的任何内容时,每个部分都是分开的,它们将是一个RegExp或String。

数组中的第一个对象([0])将是找到第一个“/”之前的文本。

然后我return s,所以eval();将返回正确的输出。