I want to save the image inside the div specified in the code. But using the code below i"m getting some other portion rendered. Is this the correct way to do it? I'm just a beginner in phantomjs. So Please help.
var page = require('webpage').create();
page.open("http://n1k0.github.io/casperjs/#phantom_Casper_captureSelector", function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
var clipRect = page.evaluate(function () {
return document.querySelector(".span7 demo").getBoundingClientRect(); });
page.clipRect = {
top: clipRect.top,
left: clipRect.left,
width: clipRect.width,
height: clipRect.height
};
window.setTimeout(function () {
page.render('capture.png');
phantom.exit();
}, 200);
}
});
I believe what you should do here is surround your return-object with JSON.stringify.
or getting the contents of the div
You can easily capture an element with an ID too. Just replace
getElementsByClassName("classname")[0]
bydocument.getElementById('divID')
. A full working example would be:This might be completely wrong but the link that I provided in my comment does it like this:
Change
to:
EDIT
Okay so I wanted to figure this one out and here's the code that works for me. I'm not familiar with the phantomjs api to use querySelector so I ended up using
getElementsByClassName
which is pretty much the same.