如果加载vBulletin(3.6.8)js feed,例如http://www.example.com/forum/external.php?type=js你会得到这样的输出:
function thread(threadid, title, poster, threaddate, threadtime) {
this.threadid = threadid;
this.title = title;
this.poster = poster;
this.threaddate = threaddate;
this.threadtime = threadtime;
}
var threads = new Array(15); threads[0] = new thread(370145, ...rest of threads in an array...);
这个函数有什么用处以及从javascript(Node.js)评估这个JS的安全方法,因为eval()可能不安全。
var phantom = require('phantom');
phantom.create(function(ph) {
return ph.createPage(function(page) {
return page.open("http://www.example.com/forum/external.php?type=js&forumids=1&lastpost=1", function(status) {
console.log("opened page? ", status);
return page.get('plainText', function(content){
console.log(content);
eval(content); //danger!
console.log(thread);
return ph.exit();
});
});
});
});
答案 0 :(得分:1)
您可以在外部加载script
标记,然后访问threads
数组。
<script src="/path/to/external.php"></script>
<script>
threads.forEach(function(thread) {
//do something with thread, has the objects listed in thread()
}
</script>