Skip to content

Instantly share code, notes, and snippets.

@unique1984
Forked from asimmittal/scrapeUsingJQuery.js
Created March 9, 2019 12:36
Show Gist options
  • Save unique1984/11296e2bc830ab55a11de0b29ad46055 to your computer and use it in GitHub Desktop.
Save unique1984/11296e2bc830ab55a11de0b29ad46055 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