简体   繁体   English

使用 Phantomjs 发布请求

[英]Post request with Phantomjs

I use the following Node.js module https://www.npmjs.com/package/phantom我使用以下 Node.js 模块https://www.npmjs.com/package/phantom

The problem is I don't know how to make a post request in order to login (or at least I need to fill the login form and click the button).问题是我不知道如何发出帖子请求才能登录(或者至少我需要填写登录表单并单击按钮)。

How can I do it?我该怎么做? If not possible, is there any Node.js module that can be used to make post request or click a button on the page如果不可能,是否有任何 Node.js 模块可用于发布请求或单击页面上的按钮

You don't need any node package.您不需要任何节点包。

"use strict";
var page = require('webpage').create(),
    server = 'http://posttestserver.com/post.php?dump',
    data = 'universe=expanding&answer=42';

page.open(server, 'post', data, function (status) {
    if (status !== 'success') {
        console.log('Unable to post!');
    } else {
        console.log(page.content);
    }
    phantom.exit();
});

Source:Here来源:这里

First, you have to download PhantomJS from here .首先,你必须从这里下载 PhantomJS。 Install it and then move the executable from the bin folder to the PATH of your file.安装它,然后将可执行文件从bin文件夹移动到文件的PATH Finally, open a new file, pastethis code , and run from your command prompt: phantomjs [name of your file] .最后,打开一个新文件,粘贴此代码,然后从您的命令提示符运行: phantomjs [name of your file]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM