Created
December 22, 2018 12:15
-
-
Save Lyuji282/ccfd8a4314991a081bafd3e7f1ae4f0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer'); | |
const tweetText = process.argv[2] | |
const twitterId = process.argv[3] | |
const twitterPassWord = process.argv[4] | |
const tweet = async (tweetText) => { | |
try { | |
const browser = await puppeteer.launch({headless: true, slowMo: 100, args: ['--no-sandbox']}); | |
const page = await browser.newPage() | |
await page.goto("https://twitter.com/?lang=ja") | |
const navigationPromise = page.waitForNavigation() | |
await navigationPromise | |
const loginButton = '#doc > div > div.StaticLoggedOutHomePage-content > div.StaticLoggedOutHomePage-cell.StaticLoggedOutHomePage-utilityBlock > div.StaticLoggedOutHomePage-signupBlock > div.StaticLoggedOutHomePage-noSignupForm > div > a.js-nav.EdgeButton.EdgeButton--medium.EdgeButton--secondary.StaticLoggedOutHomePage-buttonLogin' | |
await page.waitForSelector(loginButton) | |
await page.click(loginButton) | |
const mainInput = "#page-container > div > div.signin-wrapper > form > fieldset > div:nth-child(2) > input" | |
await page.waitForSelector(mainInput) | |
await page.type(mainInput, twitterId) | |
const passInput = "#page-container > div > div.signin-wrapper > form > fieldset > div:nth-child(3) > input" | |
await page.waitForSelector(passInput) | |
await page.type(passInput, twitterPassWord) | |
const submitButton = "#page-container > div > div.signin-wrapper > form > div.clearfix > button" | |
await page.waitForSelector(submitButton) | |
await page.click(submitButton) | |
await navigationPromise | |
await page.waitForSelector('#global-new-tweet-button') | |
await page.click('#global-new-tweet-button'); | |
await page.waitForSelector('#Tweetstorm-tweet-box-0 > div.tweet-box-content > div.tweet-content > div.RichEditor.RichEditor--emojiPicker.is-fakeFocus > div.RichEditor-container.u-borderRadiusInherit > div.RichEditor-scrollContainer.u-borderRadiusInherit > div.tweet-box.rich-editor.is-showPlaceholder') | |
await page.type('#Tweetstorm-tweet-box-0 > div.tweet-box-content > div.tweet-content > div.RichEditor.RichEditor--emojiPicker.is-fakeFocus > div.RichEditor-container.u-borderRadiusInherit > div.RichEditor-scrollContainer.u-borderRadiusInherit > div.tweet-box.rich-editor.is-showPlaceholder', | |
tweetText); | |
await page.click('#Tweetstorm-tweet-box-0 > div.tweet-box-content > div.TweetBoxToolbar > div.TweetBoxToolbar-tweetButton > span > button.SendTweetsButton.EdgeButton.EdgeButton--primary.EdgeButton--medium.js-send-tweets'); | |
await page.waitFor(1000 * 5) | |
await browser.close() | |
} catch (e) { | |
console.log(e) | |
} | |
process.exit(0) | |
} | |
(async () => { | |
await tweet(tweetText) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment