Get the HTML from a web page.
var HTTP = require('machinepack-http');
// Get the HTML from a web page.
HTTP.getWebpageHtml({
url: 'http://www.example.com/games/search?q=minecraft&page=14',
headers: {},
}).exec({
// An unexpected error occurred.
error: function (err) {
},
// A non-2xx status code was returned from the server.
non200Response: function (result) {
},
// Unexpected connection error: could not send or receive HTTP request.
requestFailed: function () {
},
// OK.
success: function (result) {
},
});
The URL of the web page to fetch.
'http://www.example.com/games/search?q=minecraft&page=14'
Custom headers to include in the request (e.g. {"X-Auth": "k3yboardc4t"}).
{}
An unexpected error occurred.
A non-2xx status code was returned from the server.
{
statusCode: 404,
headers: {},
body: '...[{"maybe some JSON": "like this"}] (but could be any string)'
}
Unexpected connection error: could not send or receive HTTP request.
OK.
'<html><body><h1>Hello world</h1></body></html>'