Last active
December 16, 2017 11:01
-
-
Save noopkat/b220d47e7a4988d9f5538882f3077dd9 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 statusTextSelector = '.someClassname'; | |
const trackingUrl = 'http://ozcouriers.com.au'; | |
const extractStatus = async () => { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto(trackingUrl, {waitUntil: 'networkidle2'}); | |
await page.waitFor(statusTextSelector); | |
const statusText = await page.evaluate((statusTextSelector) => { | |
const statusDiv = document.querySelector(statusTextSelector); | |
// returned data must be valid JSON | |
return [statusDiv.textContent]; | |
}, statusTextSelector); | |
await browser.close(); | |
return statusText.join(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment