Last active
August 16, 2022 20:21
-
-
Save qqpann/92e70595abfcff222e8ecce21926ff8c to your computer and use it in GitHub Desktop.
Puppeteer 1.0.0対応 ヘッドレスChrome逆引きクイックスタート ref: https://qiita.com/qiugits/items/ad1e2de07237ced141c4
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
mkdir try-puppeteer | |
cd try-puppeteer | |
npm i --save 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
const out = await page.evaluate(() => document.querySelector('.errmsg').innerText); | |
console.log(out); |
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
await page.screenshot({path: './screenshot.png', fullPage: true}); |
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
puppeteer.launch({headless: false}); |
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
puppeteer.launch({headless: false}); |
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
await page.goto('https://twitter.com/qiugits'); |
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
await page.type('input[name="code"]', 'Hello'); |
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
await page.click('input[name="button"]'); |
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
await page.waitFor('input'); |
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
await page.waitFor('.success, .error'); |
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
if (await page.$('div.errmsg')) { /* do something */ } |
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
if (await page.$$eval('input', inputs => inputs.length) == 2) { /* do something */ } |
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
const puppeteer = require('puppeteer'); | |
// 非同期処理 | |
(async() => { | |
// 非同期処理で前後の順番を保つには、awaitをいちいち使う | |
const browser = await puppeteer.launch(); // ブラウザをHeadlessで起動 | |
const page = await browser.newPage(); // このpageに | |
// * * * | |
// pageに対して操作する | |
// * * * | |
browser.close(); // ブラウザを閉じる | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment