【问题标题】:Retrieve all forms on Webpage检索网页上的所有表单
【发布时间】:2013-02-11 17:16:27
【问题描述】:

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

谢谢

【问题讨论】:

    标签: phantomjs zombie.js casperjs


    【解决方案1】:

    就这么简单

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

    【讨论】:

      猜你喜欢
      • 2020-04-21
      • 2022-01-09
      • 2010-12-15
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 2019-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多