我是编程的新手,我正在尝试按照教程来抓取Craigslist并从那里获取信息,然后将其打印到控制台/然后文件。console.log()在Windows 10中使用NodeJS,但在Ubuntu中却无法使用。我见过人们使用函数来打印它,但是我不知道如何在我的小项目中完成它。
这是我的文件内容:
let jquery = require('jquery')
let Nightmare = require('nightmare'),
nightmare = Nightmare()
nightmare.goto('https://vancouver.craigslist.org/search/jjj?postedToday=1')
.wait(3000)
.evaluate(function() {
let items = [];
$('.result-title').each(function() {
item = {}
item["title"] = $(this).text()
item["link"] = $(this).attr("href")
items.push(item)
})
return items
})
.end()
.then(function(items) {
for (item in items) {
console.log(items[item].title)
console.log(items[item].link)
console.log("\n")
}
});
有人可以帮忙吗?谢谢
如果您在脚本顶部console.log
处显示任何内容,您是否在终端上看到任何内容?
例如:
console.log('foobar') // add this line
let jquery = require('jquery')
// etc
如果这样做,请在最终的console.log(items)
回调中尝试.then
。你在那看到什么吗?