为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用PhantomJS提交表单

如何使用PhantomJS提交表单

12345678_0001 2019-10-23 14:33:24
我正在尝试使用phantomJS(真棒的工具btw!)为具有登录凭据的页面提交表单,然后将目标页面的内容输出到stdout。我可以使用幻像访问该表单并成功设置其值,但是我不太确定提交表单并输出后续页面内容的正确语法。到目前为止,我有:var page = new WebPage();var url = phantom.args[0];page.open(url, function (status) {  if (status !== 'success') {      console.log('Unable to access network');  } else {    console.log(page.evaluate(function () {      var arr = document.getElementsByClassName("login-form");      var i;      for (i=0; i < arr.length; i++) {        if (arr[i].getAttribute('method') == "POST") {          arr[i].elements["email"].value="mylogin@somedomain.com";          arr[i].elements["password"].value="mypassword";          // This part doesn't seem to work. It returns the content          // of the current page, not the content of the page after           // the submit has been executed. Am I correctly instrumenting          // the submit in Phantom?          arr[i].submit();          return document.querySelectorAll('html')[0].outerHTML;        }      }      return "failed :-(";    }));  }  phantom.exit();}
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 609 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信