カスタム User-agent 値でのみPhantom.jsで動作するコードがあります。しかし、このコードをNode.jsのnpm ファントムでラップしようとすると、User-agent の値の設定に問題が発生します。モジュールの説明から理解したように、このp.page.set('settings', { ... }) のようになります
サンプルコードでも機能しません:
var phantom = require('phantom');
phantom.create(function(ph) {
return ph.createPage(function(page) {
return p.page.set('settings', {userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36'});
// or p.page.set('settings.userAgent', 'Mozilla ....');
return page.open("http://www.google.com", function(status) {
return page.evaluate((function() {
return document.title;
}), function(result) {
console.log('Page title is ' + result);
return ph.exit();
}); }); }); });
このコードをどこに挿入する必要がありますか - phantom.createの後またはph.createPageの後、およびエラーが返される理由
stream.js:94
throw er; // Unhandled stream error in pipe.
^
ReferenceError: p is not defined