NODE.JS-尝试使用节点从IMDB中删除电影。当我尝试在控制台中输入电影名称时,它不会动态报废

时间:2016-05-06 16:22:06

标签: node.js npm-install npm-request

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);

0 个答案:

没有答案