Created
November 17, 2017 00:32
-
-
Save foundAhandle/4d58b0fb928a8c05a37c07f6a4c8eeef to your computer and use it in GitHub Desktop.
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
const puppeteer = require('puppeteer'); | |
const SURGEON_PATH = './node_modules/surgeon'; | |
const s = require(SURGEON_PATH).default; | |
(async() => { | |
const browser = await puppeteer.launch({ headless: false }); | |
const page = await browser.newPage(); | |
await page.setViewport({ width: 1280, height: 600 }); | |
page.on('console', (msg) => console.log(msg.text)); | |
const x = s(); | |
const selector = '[sitetranslationname="$barstate_80"]'; | |
// expose Surgeon - https://github.com/gajus/surgeon | |
await page.exposeFunction('surgeon', html => { | |
const result = x(`sm ${selector} | rtc`, html); | |
console.log(result); | |
}); | |
await page.goto('https://www.lw.com/people/mary-rose-alexander'); | |
await page.waitForSelector(selector); | |
const html = await page.content(); | |
await page.evaluate(html => { window.surgeon(html); }, html) | |
console.log('-- DONE --'); | |
await browser.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment