Skip to content

Instantly share code, notes, and snippets.

@vsemozhetbyt
Last active February 3, 2019 18:10
Show Gist options
  • Select an option

  • Save vsemozhetbyt/5b1afdbc90b79cb50127907327218b8b to your computer and use it in GitHub Desktop.

Select an option

Save vsemozhetbyt/5b1afdbc90b79cb50127907327218b8b to your computer and use it in GitHub Desktop.

Revisions

  1. vsemozhetbyt revised this gist Feb 3, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions parse_fmponline.js
    Original file line number Diff line number Diff line change
    @@ -29,9 +29,9 @@ const puppeteer = require('puppeteer');

    await Promise.all([doSearch, isSearchComplete]);

    const data = await resultsFrame.evaluate(() => {
    return document.querySelector('div.innerPageWrapper table').innerText;
    });
    const data = await resultsFrame.evaluate(
    () => document.querySelector('div.innerPageWrapper table').innerText
    );

    console.log(data.trim().replace(/\s+/g, ' '));

  2. vsemozhetbyt renamed this gist Feb 3, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. vsemozhetbyt created this gist Feb 3, 2019.
    42 changes: 42 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    '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(() => {
    return document.querySelector('div.innerPageWrapper table').innerText;
    });

    console.log(data.trim().replace(/\s+/g, ' '));

    await browser.close();
    } catch (err) {
    console.error(err);
    }
    })();