我尝试过了。我要抓取登录文字。可以通过id
获得
文本。我在网上搜索。 spookyjs有助于刮擦启用JavaScript的网站。这是我的代码,但无法获得结果。此代码始终返回空值。
try {
var Spooky = require('spooky');
} catch (e) {
var Spooky = require('../lib/spooky');
}
var spooky = new Spooky({
child: {
transport: 'http'
},
casper: {
logLevel: 'debug',
verbose: true
}
}, function (err) {
if (err) {
e = new Error('Failed to initialize SpookyJS');
e.details = err;
throw e;
}
spooky.start(
'https://www.youtube.com/');
spooky.then(function () {
this.emit('hello', 'Hello, from ' + this.evaluate(function () {
return document.getElementById("text").textContent;
}));
});
spooky.run();
});
spooky.on('error', function (e, stack) {
console.error(e);
if (stack) {
console.log(stack);
}
});
spooky.on('hello', function (greeting) {
console.log(greeting);
});