Если я знаю, что идентификатор элемента „сноска“, я могу использоватьКак получить все элементы координаты
document.getElementById("footer").getBoundingClientRect();
, чтобы получить элемент „сноска“ координаты.
Существует весь код
var page = require('webpage').create();
page.open("https://stackoverflow.com/questions/18657615/how-to-render-an-html-element-using-phantomjs", function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(function() {
//Heres the actual difference from your code...
var bb = page.evaluate(function() {
//return document.body.getBoundingClientRect();
return document.getElementById("footer").getBoundingClientRect();
});
page.clipRect = {
top: bb.top,
left: bb.left,
width: bb.width,
height: bb.height
};
console.log(bb.top);
console.log(bb.left);
console.log(bb.width);
console.log(bb.height);
page.render('capture.png');
phantom.exit();
}, 200);
}
});
результатом является
4004,6875
632,5
Я должен знать page есть элемент, идентификатор "сноска" , Если есть неизвестная веб-страница, я не знаю никакой информации на веб-странице. Как я могу получить все координаты элемента.
Возможно, traversing the dom может помочь, но я всегда получаю ошибки. Я не знаю, как правильно слить код.
Вы так хорошо. Большое спасибо! –