Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Last active December 30, 2015 19:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamemomonga/7875215 to your computer and use it in GitHub Desktop.
Save mamemomonga/7875215 to your computer and use it in GitHub Desktop.
'use strict';
var page = require('webpage').create();
page.open('https://tumblr.com',function(){
page.render('example.png');
phantom.exit();
});
'use strict';
var page = require('webpage').create();
// 画面サイズを設定
page.viewportSize = { width: 1024, height: 768 };
page.open('https://tumblr.com',function(){
page.render('example.png');
phantom.exit();
});
'use strict';
(function(){
var Controls=function(){
// ページを作成
// https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage
this.webpage=require('webpage').create();
// ページのサイズを変更
this.webpage.viewportSize = { width: 1024, height: 768 };
// ページの中とこっちは直接やりとりできないので、
// ページのコンソールになんか出たらこっちでも見えるようにする
this.webpage.onConsoleMessage = function(msg) {
console.log(' - '+msg);
};
// タンブラアカウント
this.signup={
email: 'メールアドレス',
password: 'パスワード'
};
};
Controls.prototype={
run: function(){
var t=this;
console.log('ログインページへ移動');
t.webpage.open('https://www.tumblr.com/login',function(){
t.login();
});
},
login: function() {
var t=this;
console.log('ログインページ');
// webpage.evaluateでページの中でJavaScriptを実行させる
var title=t.webpage.evaluate(function(){
return document.title;
});
console.log("ページタイトル: "+title);
console.log('画面をキャプチャ capture1');
t.webpage.render('caputure1.png');
console.log("メールアドレスとパスワードを入れて");
// webpage.evaluateはJSONとかシリアライズできるもののみ受け渡しできるらしい
t.webpage.evaluate( function(signup){
var d=document;
// document.getElementByIdでIDからDOMを取得
d.getElementById('signup_email').value = signup.email;
d.getElementById('signup_password').value = signup.password;
d.getElementById('signup_forms_submit').click();
console.log('クリック');
}, t.signup );
console.log('20秒待ってから');
setTimeout(function() {
console.log('画面をキャプチャ capture2');
t.webpage.render('caputure2.png'); // なんか長い
t.finish();
},20000);
},
finish: function() {
console.log('終了');
phantom.exit();
}
};
var controls=new Controls();
controls.run();
})();
'use strict';
(function(){
var Controls=function(){
// ページを作成
// https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage
this.webpage=require('webpage').create();
// ページのサイズを変更
this.webpage.viewportSize = { width: 1024, height: 768 };
// ページの中とこっちは直接やりとりできないので、
// ページのコンソールになんか出たらこっちでも見えるようにする
this.webpage.onConsoleMessage = function(msg) {
console.log(' - '+msg);
};
// タンブラアカウント
this.signup={
email: 'メールアドレス',
password: 'パスワード'
};
// メンバーブログ名
this.member_blog_name='ブログ名(xxxx.tumblr.comのxxxx部分)';
// 招待状を送るメールアドレス
this.invite_email='メールアドレス';
};
Controls.prototype={
run: function(){
var t=this;
console.log('ログインページへ移動');
t.webpage.open('https://www.tumblr.com/login',function(){
t.login();
});
},
login: function() {
var t=this;
console.log('ログインページ');
// webpage.evaluateでページの中でJavaScriptを実行させる
var title=t.webpage.evaluate(function(){
return document.title;
});
console.log("ページタイトル: "+title);
console.log('画面をキャプチャ capture1');
t.webpage.render('caputure1.png');
console.log("メールアドレスとパスワードを入れて");
// webpage.evaluateはJSONとかシリアライズできるもののみ受け渡しできるらしい
t.webpage.evaluate( function(signup){
var d=document;
// document.getElementByIdでIDからDOMを取得
d.getElementById('signup_email').value = signup.email;
d.getElementById('signup_password').value = signup.password;
d.getElementById('signup_forms_submit').click();
console.log('クリック');
}, t.signup );
console.log('20秒待ってから');
setTimeout(function() {
console.log('画面をキャプチャ capture2');
t.webpage.render('caputure2.png'); // なんか長い
console.log('メンバーページに移動');
t.webpage.open('http://www.tumblr.com/blog/'+t.member_blog_name+'/members',function(){
t.members();
});
},20000);
},
members: function() {
var t=this;
console.log('メンバーページ');
t.webpage.evaluate(function(invite_email){
var d=document;
// フォームにメールアドレスを入れる
// document.querySelectorでCSSパスからDOMを取得
// FireBugの「CSSのパスをコピー」を使えばよい
d.querySelector('html#logged_in.no_js body#dashboard_group_members.dashboard_group_members div#container div#content.clearfix div#left_column.left_column div.white_pane div.white_pane_controls form input.text_field').value=invite_email;
console.log('招待ボタンをクリック');
d.getElementById('invite_button').click();
},t.invite_email);
console.log('10秒待ってから');
setTimeout(function() {
console.log('画面をキャプチャ capture3');
t.webpage.render('caputure3.png');
t.invite_url();
},10000);
},
invite_url: function() {
var t=this;
console.log('招待URLを取得');
var url=t.webpage.evaluate(function(){
return document.querySelector('html#logged_in.no_js body#dashboard_group_members.dashboard_group_members div#container div#content.clearfix div#left_column.left_column div.notice div input').value;
});
console.log("招待URL: "+url);
t.finish();
},
finish: function() {
console.log('終了');
phantom.exit();
}
};
var controls=new Controls();
controls.run();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment