【发布时间】:2017-11-15 17:22:53
【问题描述】:
我在 php 上使用 casperjs 和 phantomjs 在提取任何链接之前呈现网页,这样通常所有由 javascript 创建的链接都会出来,我可以看到它们,但在这个网站上看不到: centralcanadaclassics(.)com
这是我正在使用的 CasperJS 的 JS:
var xpath = require('casper').selectXPath;
var casper = require('casper').create({
pageSettings: {
loadImages: false,
webSecurityEnabled: false
},
verbose: true,
logLevel: 'debug',
colorizerType: 'Dummy'
});
casper.userAgent('casper');
casper.start().then(function() {
this.open('http://www.centralcanadaclassics.com', {
headers: {
'Accept': 'text/html'
}
});
});
casper.then(function () {
this.echo('[CURRENT_URL]' + this.getCurrentUrl());
this.echo('[CURRENT_TITLE]' + this.getTitle());
this.echo('[CURRENT_PAGE_CONTENT]' +
this.getPageContent().replace(new RegExp('\r?\n','g'), ''));
this.echo('[CURRENT_HTML]' + this.getHTML().replace(new RegExp('\r? \n','g'), ''));
this.echo('[CURRENT_HEADERS]' + JSON.stringify(this.currentResponse.headers));
this.echo('[CURRENT_STATUS]' + this.currentResponse.status);
this.echo('[CURRENT_STATUS_TEXT]' + this.currentResponse.statusText);
this.echo('[CURRENT_COOKIES]' + JSON.stringify(phantom.cookies));
});
casper.run();
所以最后所有内容都保持不变,不会呈现该页面。 请解释原因?
【问题讨论】:
-
那么,您想提取该页面上的所有链接吗?还有你疑惑为什么在 casperjs 输出中看不到链接,而在普通浏览器中却可以看到?