IMacro Scripting - 如何使用javascript读取本地.txt文件 [英] IMacro Scripting - How to read a local .txt file using javascript

查看:136
本文介绍了IMacro Scripting - 如何使用javascript读取本地.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有这个 IMacro 脚本工具,如果你想使用javascript自动执行一些网页
页面访问。

There is this IMacro scripting tool, if you want to automate some web page visits by using javascript.

我想让我的javascript从本地.txt文件中读取
(不是.cvs文件,格式不正确..我想搜索它可能是
与正则表达式..)
并根据该读数,该脚本将在IMacros做一些工作..(例如调用一些网站
url等...)

I would like to have my javascript to read from a local .txt file (not a .cvs file and not well formatted.. I would like to search in it probably with a regular expression..) and based on that reading, the script will do some job in IMacros.. (e.g call some web site url etc..)

你们有什么想法可以做到这一点吗?我正在做一切
本地的,这是我本地浏览器从我的本地硬盘读取..它应该以某种方式可以
..但是怎么样?

Do you guys have any idea how this can be done ? I am doing everything local and that is my local browser reading from my local hard drive.. it should be somehow possible.. but how ?

推荐答案

是的,你可以用imacros做,但你需要从javascript.js文件中调用它。将您的内容加载为一个块,然后您可以使用javascript indexOf方法在文本中查找字符串并执行if语句。
文本示例(在你的txt文件中):
hello world!

Yes you can do it with imacros, but you need to call it from javascript.js file. load your content as one block, then you can use javascript indexOf method to find the string in the text and perform if statement. Text example (inside your txt file): "hello world!"

var load;
load =  "CODE:";
load +=  "set !extract null" + "\n"; 
load +=  "SET !DATASOURCE text.txt" + "\n"; 
load +=  "SET !DATASOURCE_COLUMNS 1" + "\n"; 
load +=  "SET !DATASOURCE_LINE 1" + "\n"; 
load +=  "SET !extract {{!col1}}" + "\n";
iimPlay(load);
var s=iimGetLastExtract(0);
var index=s.indexOf("w");
if (index>0){
do your code;
}

这篇关于IMacro Scripting - 如何使用javascript读取本地.txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆