Created
February 21, 2019 11:55
-
-
Save quanon/e3c5787a14c8e2b3b1731dd824a50f15 to your computer and use it in GitHub Desktop.
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'); | |
const moment = require('moment'); | |
const today = moment(); | |
const url = 'https://www.panasonic.com/jp/corporate/history/founders-quotes.html'; | |
const titleSelector = '.h2Title'; | |
const bodySelector = '#day-after-day-content'; | |
(async () => { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto(`${url}?${today.format('MMDD')}`); | |
await page.waitForSelector(titleSelector); | |
let title = await page.evaluate(titleSelector => document.querySelector(titleSelector).textContent, titleSelector) | |
title = title.split(/\s/).pop(); | |
await page.waitForSelector(bodySelector); | |
const body = await page.evaluate(bodySelector => document.querySelector(bodySelector).textContent, bodySelector); | |
console.log(`${today.format('MM/DD')} ${title} | |
${body}`); | |
await browser.close() | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment