Skip to content

Instantly share code, notes, and snippets.

@asimmittal
Created October 4, 2017 16:01
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save asimmittal/2942cc4fc537406819312a10ea9dbc21 to your computer and use it in GitHub Desktop.
Save asimmittal/2942cc4fc537406819312a10ea9dbc21 to your computer and use it in GitHub Desktop.
JqueryScraper
console.log("---> Running");
const curl = require("curl");
const jsdom = require("jsdom");
const url = "http://www.imdb.com/list/ls004489992/";
curl.get(url, null, (err,resp,body)=>{
if(resp.statusCode == 200){
parseData(body);
}
else{
//some error handling
console.log("error while fetching url");
}
});
function parseData(html){
const {JSDOM} = jsdom;
const dom = new JSDOM(html);
const $ = (require('jquery'))(dom.window);
//let's start extracting the data
var items = $(".list_item");
for(var i = 0; i < items.length; i++){
var innerInfo = $(items[i]).children('.info');
var movieName = $($(innerInfo).find('a')[0]).html();
var movieYear = $($(innerInfo).find('.year_type')[0]).html();
console.log(i + " -> " + movieYear + ":" + movieName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment