嗨,我正在使用 PhantomJs 从 url 捕获屏幕。但似乎结果不准确。
PhantomJS版本:1.9.8,操作系统:Ubuntu 14
使用下面的代码,我尝试从网址捕获屏幕,但它似乎没有提供完美的屏幕截图。 或者我做错了什么?
参见该网站的标题部分和屏幕截图..两者并不相似。
结果屏幕截图:http://www.awesomescreenshot.com/image/2275399/7cf995d2e287cb87c4ca4895b6b69934
我试图捕获的网站:http://www.whiteboardexplainers.com/
var system = require("system");
if (system.args.length > 0) {
var page = require('webpage').create();
page.viewportSize = {width: 1280, height: 1024};
page.open(system.args[1], function() {
var pageTitle = system.args[1].replace(/http.*\/\//g, "").replace("www.", "").split("/")[0]
var filePath = "pageTitle + '.png';
window.setTimeout(function () {
page.evaluate(function() {
document.body.bgColor = 'white';
});
page.render(filePath);
console.log(filePath);
phantom.exit();
}, 200);
});
}
最佳答案
您使用了非常过时的 PhantomJS 版本。考虑到这一点,屏幕截图看起来非常好。升级到现代 PhantomJS 版本:2.1.1 甚至更好的 2.5 beta。在这里获取它们:PhantomJS downloads archive .
但即使是现代版本也不支持显示视频,因此无论如何都行不通。
就您而言,它似乎不相关,但通常是:建议 declare a useragent string现代浏览器的一部分。否则,许多网站都会显示其页面的移动版本。
关于javascript - 使用 phantomjs 的屏幕截图与在浏览器中看到的不准确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42688714/