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);
質問する
271 次