有对项目的bug跟踪另一个解决办法:
https://github.com/ariya/phantomjs/issues/10364#issuecomment-14992612
所有你需要做的就是渲染到文件之前移除具有低透明度的所有页面元素:
diff --git a/examples/rasterize.js b/examples/rasterize.js
index fcd74cd..dcc81d4 100644
--- a/examples/rasterize.js
+++ b/examples/rasterize.js
@@ -19,6 +19,16 @@ if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Unable to load the address!');
} else {
window.setTimeout(function() {
+ // Remove all low-opacity paths. see PhantomJS issue #364
+ page.evaluate(function() {
+ var paths = document.getElementsByTagName("path");
+ for (var i = paths.length - 1; i >= 0; i--) {
+ var path = paths[i];
+ var strokeOpacity = path.getAttribute('stroke-opacity');
+ if (strokeOpacity != null && strokeOpacity < 0.2)
+ path.parentNode.removeChild(path);
+ }
+ });
page.render(output);
phantom.exit();
}, 200);
你可以即使您无法访问包含图形的页面源,也可以使用它来抓取图形。
您可以尝试禁用该图表的工具提示('tooltip.enabled = false')和鼠标跟踪('enabledMouseTracking = false')。 –
做到了!出色的工作,谢谢帕维尔。 –