简体   繁体   中英

Simulate browser using RingoJs

I create a server that accessing a site as if the site is accessed by a browser. Some sites that my server need to access is required the execution of javascript, my question regarding RingoJs is: can I use RingoJs runtime to execute downloaded js from the accessed site?

You can write this.

importPackage(java.net);
importPackage(java.io);
var sourceJs = "http://foo.bar.com/js/foo.js";
var url = new URL(sourceJs);

var ucon = url.openConnection();
var istream = ucon.getInputStream();
var isr = new InputStreamReader(istream, "utf-8");
var br = new BufferedReader(isr);
var line = "";
var buf = "";
while((line = br.readLine()) != null) {
     buf = buf + line + "\n";
}
eval(buf);

but, eval is very danger,if you don't know what you are doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM