私はphantomjsを初めて使用します。私はあまりにも長い間、次のものをいじっています。私は非常に単純なものが欠けていることを知っています。私は次のsitemap.xmlを持っています:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>/</loc>
<changefreq>always</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>/vehicles</loc>
<lastmod>2013-01-07</lastmod>
</url>
</urlset>
今私がやろうとしているのは、phantomjsを使用してxmlドキュメントからurl値を取得することだけです。私は以下を持っています。
page.open("sitemap.xml", function(status) {
if(status !== "success") {
console.log("Unable to open sitemap.");
} else {
// Stuck here
console.log(page.content);
}
});
xmlファイルの内容は画面に正しく印刷されますが、ドキュメントを使用してxmlを操作するにはどうすればよいですか?各URLノードの最初の子を取得できる必要があります。xmlドキュメントをDOMParserに解析しようとしましたが、正しくないようです。あなたの助けは大歓迎です。
また、phatomjsをどのようにデバッグして、オブジェクトを完全に表示できるようにしますか?たとえば、開発ツールでオブジェクトをconsole.logにすると、オブジェクトを展開して、キーと値のペアを確認できます。ターミナルはこの贅沢を提供していないと思いますか?