imacros extract and remove unwanted text

徘徊边缘 提交于 2019-12-12 03:37:42

问题


Hi Im trying to extract a price and strip the extract of some unwanted text. So that "US $149.99" becomes "149.99"

TAG POS=1 TYPE=SPAN FORM=NAME:donasub ATTR=ID:donaprice EXTRACT=TXT
SET donaprice  EVAL("var s=\"{{!EXTRACT}}\"; s.replace(\"US $\", \"\");")
SAVEAS TYPE=EXTRACT FOLDER=C:\demo FILE=donafiles.csv

I still get the full string "US $149.99" in the extract. What am I not doing right.


回答1:


You need to escape special characters with \\. In this case it is "$"

SET donaprice EVAL("var s=\"{{!EXTRACT}}\"; s.replace(\"US \\$\", \"\");")

'show your result before saving in prompt (popup box) good for checking results

PROMPT {{donaprice}}

You are re-saving the original extract which is US $149.99 in this line:

`SAVEAS TYPE=EXTRACT FOLDER=C:\demo FILE=donafiles.csv`

You have to re-add the new variable "donaprice" to EXTRACT

ADD !EXTRACT {{donaprice}}

SAVEAS TYPE=EXTRACT FOLDER=C:\demo FILE=donafiles.csv


So all together :

SET donaprice EVAL("var s=\"{{!EXTRACT}}\"; s.replace(\"US \\$\", \"\");")

ADD !EXTRACT {{donaprice}}

SAVEAS TYPE=EXTRACT FOLDER=C:\demo FILE=donafiles.csv

Hope this helps.




回答2:


SET !EXTRACT EVAL("var s = '{{!EXTRACT}}'.replace(/US \\$/, ''); s;")


来源:https://stackoverflow.com/questions/31909301/imacros-extract-and-remove-unwanted-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!