1
PhantomJSでSVGファイルとして保存しようとしているSVGタグのサンプルテストページがあります。私はPhantomJSを使ってテストページに行くことができますが、その後、どのようにsvgを見つけて保存するのか分かりません。ここで私はそれをやろうとした方法と私が立ち往生したところです。 document.getElementsByTagName( 'SVG')とのSVGタグを検索してみてください PhantomJSでSVGを保存する
- Nagivate
- ここから行うには?私はファントムが巨大な物体を返すのを見ることができますが、これで何をするべきかについて彼らのウェブサイト上で何も見つけることができません。このオブジェクトをsvgファイルに変換するにはどうすればよいですか?
testpageは次のようになります。
<HTML>
This is a Testpage. You like it, don't you?
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient id="myLinearGradient1"
x1="0%" y1="0%"
x2="0%" y2="100%"
spreadMethod="pad">
<stop offset="0%" stop-color="#00cc00" stop-opacity="1"/>
<stop offset="100%" stop-color="#006600" stop-opacity="1"/>
</linearGradient>
</defs>
<rect x="10" y="10" width="75" height="100" rx="10" ry="10"
style="fill:url(#myLinearGradient1);
stroke: #005000;
stroke-width: 3;" />
</svg>
</HTML>
とPhantomJSスクリプト
var page = require('webpage').create();
console.log('The default user agent is ' + page.settings.userAgent);
function getSVG(link, callback) {
page.open(link, function(status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
var ua = page.evaluate(function() {
return document.getElementsByTagName('svg');
});
// Don't know what to do here
}
phantom.exit();
callback();
});
}
getSVG('testpage', function() {
console.log('done');
});