检索网页上的所有表单



如何检索给定网站上存在的所有表单。特别是表单的 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();
});

另外,请注意,不能通过评估传递非基元对象。您必须在评估中完成工作。

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

最新更新