有對項目的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')。 –
做到了!出色的工作,謝謝帕維爾。 –