$ npm install
edit ID/Pass .env
$ node index.js
-
-
Save MozyOk/b06104ba6e50ed35e02482d221858f52 to your computer and use it in GitHub Desktop.
puppeteer を使ってBFにログイン処理を行うサンプル
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
MY_USER_ID=[email protected] | |
MY_PASSWORD=passpasswordpassword | |
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'); | |
require('dotenv').config(); | |
var USER_ID = process.env.MY_USER_ID; | |
var PASSWORD = process.env.MY_PASSWORD; | |
console.log('login via: ' + USER_ID); | |
const pc = { | |
'name': 'Chrome Mac', | |
'userAgent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36', | |
'viewport': { | |
'width': 1200, | |
'height': 800, | |
'deviceScaleFactor': 1, | |
'isMobile': false, | |
'hasTouch': false, | |
'isLandscape': false | |
} | |
}; | |
(async () => { | |
const browser = await puppeteer.launch({ | |
headless: false, | |
slowMo: 10, | |
}); | |
const page = await browser.newPage(); | |
await page.emulate(pc); | |
// BFページ開いて表示されるまで待機 | |
await page.goto('https://bitflyer.com/ja-jp/login') | |
await page.waitForSelector('#loginForm'); | |
// ユーザ名、パスワード入力 | |
await page.type('input[name="ctl00$MainContent$email"]', USER_ID); | |
await page.type('input[name="ctl00$MainContent$password"]', PASSWORD); | |
// ログイン | |
await page.click('input[name="ctl00$MainContent$Button1"]'); | |
// スクショはお好みで | |
// await page.screenshot({path: 'tmp/login.png', fullPage: true}); | |
// 2段階認証があったら、ログイン後の電話番号認証の送信 | |
await page.click('input[name="ctl00$MainContent$ctl00"]'); | |
// Home画面かどうかをチェック | |
await page.waitForNavigation({timeout: 60000, waitUntil: "domcontentloaded"}); | |
// スクショはお好みで | |
// await page.screenshot({path: 'tmp/home.png', fullPage: true}); | |
// 取引履歴ページに遷移 | |
await page.goto('https://bitflyer.com/ja-jp/ex/TradeHistory'); | |
// DLボタンをクリック | |
await page.click('#MainContent_DownloadReportButton') | |
// ブラウザは手動で終了する | |
// await browser.close(); | |
})(); |
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
{ | |
"name": "bf-puppeteer", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"dotenv": "^6.1.0", | |
"puppeteer": "^1.9.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment