-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter.js
executable file
·46 lines (39 loc) · 1.43 KB
/
twitter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @name Twitter
*
* @desc Logs into Twitter. Provide your username and password as environment variables when running the script, i.e:
* `TWITTER_USER=myuser TWITTER_PWD=mypassword node twitter.js`
*
*/
const puppeteer = require("puppeteer");
const screenshot = "twitter.png";
try {
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 800 });
const navigationPromise = page.waitForNavigation();
await page.goto("https://twitter.com/");
await page.waitForSelector(
".StaticLoggedOutHomePage-cell > .StaticLoggedOutHomePage-login > .LoginForm > .LoginForm-username > .text-input"
);
await page.type(
".StaticLoggedOutHomePage-cell > .StaticLoggedOutHomePage-login > .LoginForm > .LoginForm-username > .text-input",
"tim_nolet"
);
await page.type(
".StaticLoggedOutHomePage-cell > .StaticLoggedOutHomePage-login > .LoginForm > .LoginForm-password > .text-input",
"spWF9G5%"
);
await page.click(
".StaticLoggedOutHomePage-content > .StaticLoggedOutHomePage-cell > .StaticLoggedOutHomePage-login > .LoginForm > .EdgeButton"
);
await navigationPromise;
await page.waitForSelector("#timeline");
await page.screenshot({ path: screenshot });
console.log("saved");
await browser.close();
})();
} catch (error) {
console.error(error);
}