Created
November 20, 2019 05:59
-
-
Save YusukeIwaki/a4eafd424d6dced707d7f7112c80b5b2 to your computer and use it in GitHub Desktop.
ぐぐれかすをpuppeteerでサクッと
This file contains hidden or 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
// yarn init -y | |
// yarn add puppeteer-core | |
const puppeteer = require("puppeteer-core"); | |
const launchChrome = puppeteer.launch({ | |
// MacにインストールされているChromeを使う。 | |
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', | |
// ブラウザ画面を表示しながら(ヘッドレスモードを無効にする)。 | |
headless: false, | |
args: [ | |
// ゲストセッションで操作する。 | |
"--guest", | |
// ウインドウサイズをデフォルトより大きめに。 | |
'--window-size=1280,800', | |
], | |
// 人間味のある速度で入力/操作する。 | |
slowMo: 50, | |
}); | |
launchChrome.then(async (browser) => { | |
const page = (await browser.pages())[0] || (await browser.newPage()); | |
await page.setViewport({ width: 1280, height: 800 }); | |
await page.goto("https://google.com/"); | |
await page.type("input[name='q']", "ぐぐれかす"); | |
await page.keyboard.press("Enter"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment