1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IEをMicrosoft windows based script hostとJavaScriptで自動操作しますよ。

Posted at

やりたいこと

本当はGithubを操作したかったわけではないのですが、自動&定期実行でIEを起動してログインしてフォームの入力をして送信します。

JavaScriptの準備

test.jsという名前で以下の内容を作成します。
user_nameuser_passwordに自分のGithubのアカウント情報を設定してください。
またgit_wiki_newはあなたの持っているリポジトリのwikiに移動してNewPageをクリックして出てくるページのURLを設定しましょう。

// この下を書き換えてください
var user_name = "*****"
var user_password = "*****"
var git_wiki_new = "https://github.com/*****/*****/wiki/_new"


//  Internet Explorerオブジェクトを取得(Internet Explorerの起動)
var IEApp = new ActiveXObject( "InternetExplorer.Application" );

//  Internet Explorerアプリケーションを表示
IEApp.Visible = true;


//  ページの読み込みが終わるまで処理を止める その後3秒停止
while( IEApp.Busy )
    WScript.Sleep( 500 ); 
WScript.Sleep( 3000 );


// サイトに移動
IEApp.Navigate( "https://github.com/login" );

//  ページの読み込みが終わるまで処理を止める その後3秒停止
while( IEApp.Busy )
    WScript.Sleep( 500 ); 
WScript.Sleep( 3000 );

// フォームに入力
var TextBox1 = IEApp.document.getElementById( "login_field" );
var TextBox2 = IEApp.document.getElementById( "password" );
TextBox1.value = user_name;
TextBox2.value = user_password;

// 3秒停止
WScript.Sleep( 3000 );


//  ボタンを押す
var Button = IEApp.document.getElementsByName( "commit" ).item(0);
Button.click();

//  ページの読み込みが終わるまで処理を止める その後3秒停止
while( IEApp.Busy )
    WScript.Sleep( 500 ); 
WScript.Sleep( 3000 );

/*-----------------------------------------------------------*/
// サイトに移動
IEApp.Navigate( git_wiki_new );

//  ページの読み込みが終わるまで処理を止める その後3秒停止
while( IEApp.Busy )
    WScript.Sleep( 500 ); 
WScript.Sleep( 3000 );

var Title = IEApp.document.getElementsByName( "wiki[name]" ).item(0);
Title.value = new Date();
var Editor = IEApp.document.getElementById( "gollum-editor-body" );
Editor.value = "自動入力したよ( ´_ゝ`)(´<_`  )"

// 3秒待つ
WScript.Sleep( 3000 );

var Button2 = IEApp.document.getElementById( "gollum-editor-submit" );
Button2.click();

//  ページの読み込みが終わるまで処理を止める その後3秒停止
while( IEApp.Busy )
    WScript.Sleep( 500 ); 
WScript.Sleep( 3000 );

/*-----------------------------------------------------------*/
//ログアウト
var Signout = IEApp.document.getElementsByClassName( "dropdown-signout" ).item(0);
Signout.click();

//  ページの読み込みが終わるまで処理を止める その後3秒停止
while( IEApp.Busy )
    WScript.Sleep( 500 ); 
WScript.Sleep( 3000 );

//  Internet Explorerを終了
IEApp.Quit();

// WScript.Echo( "終了" );

//  オブジェクトを解放
IEApp = null;

ここを参考にタスクスケジューラの起動までを行います。

  • 画面右側の基本タスクの作成をクリック
  • 名前と説明を適当に埋めて「次へ」
  • 毎日を選択して「次へ」
  • 開始日時を適当に5ふん後くらいで「次へ」
  • プログラムの開始を選択して「次へ」
  • 参照をクリックして先ほど作ったtest.jsを選択
  • そのまま完了まで進んでいきます。

タスクスケジューラの設定はここまでで今度はtest.jsを右クリックします。

  • 全般タブの変更をクリックして「Microsoft windows based script host」を選択します。
  • あとはPCを起動したまま待ちます。
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?