前提・実現したいこと
apiを使わずにtwitterで投稿したいです。
https://qiita.com/ko-he-8/items/1bc26fd6ecdf6a8bf946
上記のページで書かれているプログラミングを動かしたい。
(動かないのは少し古いのでtwitterの仕様が変わったためだと思います)
発生している問題・エラーメッセージ
65行目の投稿する内容を書き込む所でエラーが起きる。
その他の書き込む所(id,パスワード)はinputを指定しているが、ここだけ「contenteditable="true"」のため、勝手が分からない。
該当のソースコード
javascript
1 2var userName = "****"; 3var userPassword = "****"; 4 5 6var now = new Date(); 7 8var year = now.getYear(); // 年 9var month = now.getMonth() + 1; // 月 10var day = now.getDate(); // 日 11var hour = now.getHours(); // 時 12var min = now.getMinutes(); // 分 13var sec = now.getSeconds(); // 秒 14 15// Tweetの内容 16var tweetText = 'おはようございます' + year + '年' + month + '月' + day + '日' + hour + '時' + min + '分' + sec + '秒</strong>' + 'です'; 17 18 19// Internet Explorerオブジェクトを取得(Internet Explorerの起動) 20var ieApp = new ActiveXObject( "InternetExplorer.Application" ); 21 22// Internet Explorerアプリケーションを表示 23ieApp.Visible = true; 24 25 26// ページの読み込みが終わるまで処理を止める その後3秒停止 27while( ieApp.Busy ) 28 WScript.Sleep( 500 ); 29WScript.Sleep( 3000 ); 30 31 32// サイトに移動 33ieApp.Navigate( "https://twitter.com/?lang=ja" ); 34 35// ページの読み込みが終わるまで処理を止める その後3秒停止 36while( ieApp.Busy ) 37 WScript.Sleep( 500 ); 38WScript.Sleep( 3000 ); 39 40// ログイン 41var userNameTextBox = ieApp.document.getElementsByName( "session[username_or_email]" ).item(0) ; 42var userPasswordTextBox = ieApp.document.getElementsByName( "session[password]" ).item(0) ; 43var loginButton = ieApp.document.getElementsByClassName("js-submit").item(0) ; 44 45if(userNameTextBox !== null){ 46 47 userNameTextBox.value = userName; 48 userPasswordTextBox.value = userPassword; 49 WScript.Sleep( 500 ); 50 51 var submitEvent = ieApp.document.createEvent("HTMLEvents"); 52 submitEvent.initEvent("submit", true, true); 53 loginButton.dispatchEvent(submitEvent); 54 loginButton.click(); 55 56 // ページの読み込みが終わるまで処理を止める その後3秒停止 57 while( ieApp.Busy ) 58 WScript.Sleep( 500 ); 59 WScript.Sleep( 3000 ); 60} 61 62// Tweetする 63var tweetAreaButton = ieApp.document.getElementById("global-new-tweet-button"); 64tweetAreaButton.click(); 65WScript.Sleep( 500 ); 66var tweetTextBox = ieApp.document.getElementById("tweet-box-global").children.item(0); 67tweetTextBox.innerHTML = tweetText; 68WScript.Sleep( 3000 ); 69var tweetButton = ieApp.document.getElementsByClassName("btn primary-btn tweet-action tweet-btn js-tweet-btn").item(1) ; 70tweetButton.click(); 71 72while( ieApp.Busy ) 73 WScript.Sleep( 500 ); 74WScript.Sleep( 3000 ); 75 76//ログアウト 77var userDropdown = ieApp.document.getElementById("user-dropdown-toggle"); 78userDropdown.click(); 79WScript.Sleep( 3000 ); 80var logoutButton = ieApp.document.getElementById("signout-form"); 81logoutButton.click(); 82 83 84while( ieApp.Busy ) 85 WScript.Sleep( 500 ); 86WScript.Sleep( 3000 ); 87 88// ブラウザを終了 89ieApp.Quit(); 90 91// 解放 92ieApp = null; 93
試したこと
chromeの検証から書き込む所を調べて、classnameなどで指定する。
→エラー
補足情報(FW/ツールのバージョンなど)
twitterのアカウントを持っている必要があります。
あなたの回答
tips
プレビュー