Last active
August 29, 2015 14:17
-
-
Save niraj-shah/e3ae239194d982e938f2 to your computer and use it in GitHub Desktop.
NodeJS Example of POST
This file contains hidden or 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