var express = require('express');
var cheerio = require("cheerio");
var request = require("request");
var fs = require('fs');
var app = express();
app.get('/scrape/:movie' , function(req, res){
var movie = req.params.movie;
option = {
protocol : "http:",
host: "www.imdb.com",
pathname :"/find " ,
search: "?q=movie",
query: "q=movie"
}
var imdbUrl =url.format(option);
request(imdbUrl,function(error,request,body){
if(!error && response.statusCode==200)
{
var $ =cheerio.load(body);
var select=$(".result_text").attr("href");
}
});
urls = "http://www.imdb.com/"+ select;
console.log(urls);
request(urls,function(error,response,body){
if(!error && response.statusCode==200)
{
var $ =cheerio.load(body);
var title, release, rating, review;
var json = { title : "",review : ""};
json.title =$(".title").text();
json.review= $(".reviewSection").text();
}
fs.writeFile('output.json',JSON.stringify(json, null, 7),function(error){
if(!error)
console.log('File successfully written! - Check your project directory for the output.json file');
});
res.send('Check your console!');
});
});
app.listen(3000);
Asked
Active
Viewed 287 times
0

DisappointedByUnaccountableMod
- 6,656
- 4
- 18
- 22

kartik
- 69
- 8
-
Actually, I am trying to scrap movie contents from IMDB . but not able to make it . I am creating a URL dynamically and request for the find query and then use the first link and request that link to scrap the content. – kartik May 06 '16 at 16:26
-
You should provide some more information in your post about what you are trying to do! – Joakim Ericsson May 06 '16 at 16:31
-
Also, please reformat your code so it is all inside the code blocks. – Skam May 06 '16 at 16:32
-
I want to create a scrapper which scrap the user choice movie from IMDB in node application – kartik May 06 '16 at 19:17
-
FYI It's scrape, scraper, scraping, scraped. Not scrap/scrapper/scrapper/scrapping. – DisappointedByUnaccountableMod Jun 10 '21 at 07:12