【发布时间】:2015-05-09 16:47:17
【问题描述】:
我正在尝试使用 Casperjs 抓取此 page。我的代码的主要功能工作正常,但内容是动态加载的,我不知道如何触发它。
这就是我现在正在做的事情:
casper.waitFor(function() {
this.scrollToBottom();
var count = this.evaluate(function() {
var match = document.querySelectorAll('.loading-msg');
return match.length;
});
if (count <= 1) {
return true;
}
else {
return false
};
}, function() { // do stuff });
等待超时刚刚到期,即使我已将其增加到 20 秒,并且永远不会加载新内容。我已经尝试将此功能调整为适合我的情况:
function tryAndScroll(casper) {
casper.waitFor(function() {
this.page.scrollPosition = { top: this.page.scrollPosition["top"] + 4000, left: 0 };
return true;
}, function() {
var info = this.getElementInfo('p[loading-spinner="!loading"]');
if (info["visible"] == true) {
this.waitWhileVisible('p[loading-spinner="!loading"]', function () {
this.emit('results.loaded');
}, function () {
this.echo('next results not loaded');
}, 5000);
}
}, function() {
this.echo("Scrolling failed. Sorry.").exit();
}, 500);
}
但我无法弄清楚,我什至不确定它与这里是否相关。 有什么想法吗?
【问题讨论】:
标签: javascript web-scraping casperjs dynamic-content