我正在尝试使用nightmarejs(使用电子作为浏览器的phantomjs派生词)从Instagram个人资料页面中搜索一些信息.
目标是获取配置文件中所有图像的alt标签(例如,我只关注"显示更多"按钮之前的图像)
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true });
nightmare
.goto('https://www.instagram.com/ackerfestival/')
.evaluate(function () {
let array = [...document.querySelectorAll('._icyx7')];
return array.length;
})
.end()
.then(function (result) {
console.log(result);
})
.catch(function (error) {
console.error('Search failed:', error);
});
Run Code Online (Sandbox Code Playgroud)
这个例子有效,数组的长度为12.电子浏览器打开和关闭,所以一切都很好.但是,如果我将返回更改为只是数组,电子浏览器永远不会关闭,我没有得到console.log.
我究竟做错了什么?我想从数组或对象中的图像中获取所有信息.