Created
January 5, 2020 08:00
-
-
Save yysaki/e1ae0ebb23dc5b82c001e54c0014a40a to your computer and use it in GitHub Desktop.
booklog読書目標の取得
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
import puppeteer from 'puppeteer'; | |
const url = 'https://booklog.jp/users/{userName}/goal/{id}'; | |
async function main() { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto(url, { waitUntil: 'networkidle0' }); | |
const rows = await page.evaluate(() => { | |
const ret = Array.from(document.querySelectorAll('table.tableType2 tbody tr')) | |
.map(tr => { | |
return { | |
title: tr!.querySelector('a.titleLink')!.innerHTML, | |
readAt: tr!.querySelector('em')!.innerHTML, | |
}; | |
}); | |
return ret; | |
}); | |
await browser.close(); | |
rows | |
.sort((a, b) => Date.parse(a.readAt) - Date.parse(b.readAt)) | |
.forEach(row => console.log(`${row.readAt} ${row.title}`)); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment