这是以下错误
E:\ freelancer-work-backup \ scrapping> node index.js Screenshot of error
$ node index
module.js:341
throw err;
^
Error: Cannot find module 'require'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (E:\freelancer-work-backup\scrapping\index.js:1:83)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
index.js中的代码:
var request = require('require'),
cheerio = require('cheerio');
var url = 'grocermax.com/catalogsearch/result/…';
request(url, function(err, resp, body) {
if (!err && resp.statusCode == 200) {
console.log(body);
} else {
console.log("Failed");
}
});
答案 0 :(得分:1)
您应该将代码更改为var request = require('request')