NodeJS Example of POST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// include the libraries we need | |
var request = require('request'); | |
var cheerio = require('cheerio'); | |
// set some defaults | |
req = request.defaults({ | |
jar: true, // save cookies to jar | |
rejectUnauthorized: false, | |
followAllRedirects: true // allow redirections | |
}); | |
// POST data then scrape the page | |
req.post({ | |
url: "http://www.example.com/", | |
form: { 'foo': 'bar' }, | |
headers: { | |
'User-Agent': 'Super Cool Browser' // optional headers | |
} | |
}, function(err, resp, body) { | |
// load the html into cheerio | |
var $ = cheerio.load(body); | |
// do something with the page here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment