Skip to content

Instantly share code, notes, and snippets.

@noopkat noopkat/tracker.js
Last active Dec 16, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.