I'm using the following code to get all img tags inside a page:
"use strict";
var system = require('system');
var args = system.args;
var page = require('webpage').create();
page.onLoadStarted = function () {
console.log('Loading Page...');
};
page.onLoadFinished = function (status) {
console.log('Loading finished.');
var imgs = page.evaluate(function() {
console.log(document.images);
console.log(document.images.length);
return document.images;
});
for (var i = 0; i < imgs.length; i++){
//console.log(JSON.stringify(imgs[i]));
console.log(imgs[i]);
console.log(imgs[i].alt);
}
phantom.exit();
};
page.open(system.args[1]);
It outputs the alt text correctly as expected, but on the line:
console.log(imgs[i]);
It only outputs: "[object object]" I would expect to get all of the img tag code, if i use JSON.stringify it outputs an immensely long msg that is also not the img tag code as I want.
Can anyone explain what is going on? How am I supossed to get the img tag code?
console.log(imgs[i].outerHTML);