Skip to content

Instantly share code, notes, and snippets.

@niraj-shah niraj-shah/getIP.js
Last active Jan 21, 2016

What would you like to do?
NodeJS example of how to scrape a webpage and retrieve the details
// 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
// scrape the page
url: "",
headers: {
'User-Agent': 'Super Cool Browser' // optional headers
}, function(err, resp, body) {
// load the html into cheerio
var $ = cheerio.load(body);
// get the data and output to console
console.log( 'IP: ' + $('.inner_cntent:nth-child(1) span').text() );
console.log( 'Host: ' + $('.inner_cntent:nth-child(2) span').text() );
console.log( 'UA: ' + $('.browser span').text() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.