gas score 5
2018/07/20 13:14 投稿
contenteditable="true"の時の入力方法 |
### 前提・実現したいこと |
apiを使わずにtwitterで投稿したいです。 |
https://qiita.com/ko-he-8/items/1bc26fd6ecdf6a8bf946 |
上記のページで書かれているプログラミングを動かしたい。 |
(動かないのは少し古いのでtwitterの仕様が変わったためだと思います) |
### 発生している問題・エラーメッセージ |
65行目の投稿する内容を書き込む所でエラーが起きる。 |
その他の書き込む所(id,パスワード)はinputを指定しているが、ここだけ「contenteditable="true"」のため、勝手が分からない。 |
### 該当のソースコード |
```javascript |
var userName = "****"; |
var userPassword = "****"; |
var now = new Date(); |
var year = now.getYear(); // 年 |
var month = now.getMonth() + 1; // 月 |
var day = now.getDate(); // 日 |
var hour = now.getHours(); // 時 |
var min = now.getMinutes(); // 分 |
var sec = now.getSeconds(); // 秒 |
// Tweetの内容 |
var tweetText = 'おはようございます' + year + '年' + month + '月' + day + '日' + hour + '時' + min + '分' + sec + '秒</strong>' + 'です'; |
// 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://twitter.com/?lang=ja" ); |
// ページの読み込みが終わるまで処理を止める その後3秒停止 |
while( ieApp.Busy ) |
WScript.Sleep( 500 ); |
WScript.Sleep( 3000 ); |
// ログイン |
var userNameTextBox = ieApp.document.getElementsByName( "session[username_or_email]" ).item(0) ; |
var userPasswordTextBox = ieApp.document.getElementsByName( "session[password]" ).item(0) ; |
var loginButton = ieApp.document.getElementsByClassName("js-submit").item(0) ; |
if(userNameTextBox !== null){ |
userNameTextBox.value = userName; |
userPasswordTextBox.value = userPassword; |
WScript.Sleep( 500 ); |
var submitEvent = ieApp.document.createEvent("HTMLEvents"); |
submitEvent.initEvent("submit", true, true); |
loginButton.dispatchEvent(submitEvent); |
loginButton.click(); |
// ページの読み込みが終わるまで処理を止める その後3秒停止 |
while( ieApp.Busy ) |
WScript.Sleep( 500 ); |
WScript.Sleep( 3000 ); |
} |
// Tweetする |
var tweetAreaButton = ieApp.document.getElementById("global-new-tweet-button"); |
tweetAreaButton.click(); |
WScript.Sleep( 500 ); |
var tweetTextBox = ieApp.document.getElementById("tweet-box-global").children.item(0); |
tweetTextBox.innerHTML = tweetText; |
WScript.Sleep( 3000 ); |
var tweetButton = ieApp.document.getElementsByClassName("btn primary-btn tweet-action tweet-btn js-tweet-btn").item(1) ; |
tweetButton.click(); |
while( ieApp.Busy ) |
WScript.Sleep( 500 ); |
WScript.Sleep( 3000 ); |
//ログアウト |
var userDropdown = ieApp.document.getElementById("user-dropdown-toggle"); |
userDropdown.click(); |
WScript.Sleep( 3000 ); |
var logoutButton = ieApp.document.getElementById("signout-form"); |
logoutButton.click(); |
while( ieApp.Busy ) |
WScript.Sleep( 500 ); |
WScript.Sleep( 3000 ); |
// ブラウザを終了 |
ieApp.Quit(); |
// 解放 |
ieApp = null; |
``` |
### 試したこと |
chromeの検証から書き込む所を調べて、classnameなどで指定する。 |
→エラー |
### 補足情報(FW/ツールのバージョンなど) |
twitterのアカウントを持っている必要があります。 |