Created
October 4, 2017 16:01
-
-
Save asimmittal/2942cc4fc537406819312a10ea9dbc21 to your computer and use it in GitHub Desktop.
JqueryScraper
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
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
source; https://medium.com/@asimmittal/using-jquery-nodejs-to-scrape-the-web-9bb5d439413b