Last active
February 3, 2019 18:10
-
-
Save vsemozhetbyt/5b1afdbc90b79cb50127907327218b8b to your computer and use it in GitHub Desktop.
puppeteer script for https://www.fmponline.com/ecomm/Shop
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
'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