Skip to content

Instantly share code, notes, and snippets.

@vsemozhetbyt
Last active February 3, 2019 18:10
Show Gist options
  • Save vsemozhetbyt/5b1afdbc90b79cb50127907327218b8b to your computer and use it in GitHub Desktop.
Save vsemozhetbyt/5b1afdbc90b79cb50127907327218b8b to your computer and use it in GitHub Desktop.
'use strict';
const puppeteer = require('puppeteer');
(async function main() {
try {
const browser = await puppeteer.launch();
const [page] = await browser.pages();
await page.goto('https://www.fmponline.com/ecomm/Shop');
const inputs = {
manufacturer: 'PITCO',
partNumber: '60125401',
};
const searchFrame = page.frames().find(frame => frame.name() === 'contentsframe0');
const resultsFrame = page.frames().find(frame => frame.name() === 'mainframe');
const doSearch = searchFrame.evaluate((inputs) => {
[...document.querySelectorAll('select#searchBox_manufacturer > option')]
.find(({ innerText }) => innerText === inputs.manufacturer)
.selected = true;
document.querySelector('input#searchBox_partNumber').value = inputs.partNumber;
document.querySelector('input#searchButton').click();
}, inputs);
const isSearchComplete = resultsFrame.waitForSelector('div.innerPageWrapper table');
await Promise.all([doSearch, isSearchComplete]);
const data = await resultsFrame.evaluate(
() => document.querySelector('div.innerPageWrapper table').innerText
);
console.log(data.trim().replace(/\s+/g, ' '));
await browser.close();
} catch (err) {
console.error(err);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment