Phantomjs 检索网页上的所有表单

Phantomjs 检索网页上的所有表单,phantomjs,zombie.js,casperjs,Phantomjs,Zombie.js,Casperjs,如何检索给定网站上的所有表单。特别是表单的id和名称 谢谢你这么简单 var page = require('webpage').create(); page.open('yoursitehere', function (status) { if (status !== 'success') { console.log('unable to access network'); } else { var forms = page.evaluat

如何检索给定网站上的所有表单。特别是表单的id和名称


谢谢你这么简单

var page = require('webpage').create();
 page.open('yoursitehere', function (status) {
    if (status !== 'success') {
         console.log('unable to access network');
     } else {
        var forms = page.evaluate(function(){
            //best way here     
            return document.forms;
        }); 
           //some stuff here
        console.log(forms.length);
        console.log(forms[0].name);
    }
   phantom.exit();
});
另外,请注意,不能通过evaluate传递非基本体对象。你必须在考试中完成你的工作

注意:参数和evaluate函数的返回值必须是一个简单的基元对象。经验法则:如果可以通过JSON对其进行序列化,那么就可以了。闭包、函数、DOM节点等将不起作用