0

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

谢谢

4

1 回答 1

0

简单地用类似的东西

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 节点等将不起作用!

于 2013-02-11T09:16:27.547 回答