Commit 46882628 46882628ca57fb74b3daad8399838295e932dcf1 by Nicolas Perriault

fixed #239 - getPageContent() was broken

1 parent 5ed461e8
Subproject commit 54ebcf8d7d29559d400401f6752fc770317439a1
Subproject commit 60c0d5d1e109257f31a2ef65fcc0d1f89a54a67a
......
......@@ -28,7 +28,7 @@
*
*/
/*global CasperError console exports phantom require*/
/*global CasperError console exports phantom require __utils__*/
var colorizer = require('colorizer');
var events = require('events');
......@@ -587,7 +587,6 @@ Casper.prototype.exit = function exit(status) {
"use strict";
this.emit('exit', status);
phantom.exit(status);
return this;
};
/**
......@@ -709,12 +708,14 @@ Casper.prototype.getPageContent = function getPageContent() {
return this.page.content;
}
// for some reason webkit/qtwebkit will always enclose body contents within html tags
var match = (new RegExp('^<html><head></head><body><pre.+?>(.*)</pre></body></html>$')).exec(this.page.content);
if (!match) {
// Non-HTML response
return this.page.content;
}
return match[1];
var sanitizedHtml = this.evaluate(function checkHtml() {
if (__utils__.findOne('head').childNodes.length === 0 &&
__utils__.findOne('body').childNodes.length === 1 &&
__utils__.findOne('body pre[style]')) {
return __utils__.findOne('body pre').textContent.trim();
}
});
return sanitizedHtml ? sanitizedHtml : this.page.content;
};
/**
......