Skip to content

Instantly share code, notes, and snippets.

@vsemozhetbyt
Last active March 22, 2019 02:16
Show Gist options
  • Select an option

  • Save vsemozhetbyt/20469874edba6f1e3fe933e773c32786 to your computer and use it in GitHub Desktop.

Select an option

Save vsemozhetbyt/20469874edba6f1e3fe933e773c32786 to your computer and use it in GitHub Desktop.

Revisions

  1. vsemozhetbyt revised this gist Mar 22, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions puppeteer-kbb.js
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@ const puppeteer = require('puppeteer');
    try {
    const browser = await puppeteer.launch({ headless: false });
    const [page] = await browser.pages();
    page.setDefaultTimeout(0);

    await page.goto('https://www.kbb.com/mini/countryman/2013/cooper-s-hatchback-4d/?intent=buy-used&pricetype=private-party&mileage=34000');

  2. vsemozhetbyt revised this gist Mar 21, 2019. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion puppeteer-kbb.js
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,11 @@ const puppeteer = require('puppeteer');

    await page.goto('https://www.kbb.com/mini/countryman/2013/cooper-s-hatchback-4d/?intent=buy-used&pricetype=private-party&mileage=34000');

    await page.waitForSelector('.zipcode-input');
    await page.type('.zipcode-input', '12345');
    await page.waitForSelector('.save-zipcode');
    await page.click('.save-zipcode');
    await page.waitFor(1000);
    await page.reload();
    await page.waitForSelector('#PriceAdvisorFrame');

    @@ -21,7 +24,7 @@ const puppeteer = require('puppeteer');

    console.log(data);

    // await browser.close();
    await browser.close();
    } catch (err) {
    console.error(err);
    }
  3. vsemozhetbyt revised this gist Mar 20, 2019. 1 changed file with 10 additions and 4 deletions.
    14 changes: 10 additions & 4 deletions puppeteer-kbb.js
    Original file line number Diff line number Diff line change
    @@ -9,13 +9,19 @@ const puppeteer = require('puppeteer');

    await page.goto('https://www.kbb.com/mini/countryman/2013/cooper-s-hatchback-4d/?intent=buy-used&pricetype=private-party&mileage=34000');

    const data = await page.evaluate(() =>
    [...document.querySelectorAll('div.price')].map(elem => elem.innerText)
    );
    await page.type('.zipcode-input', '12345');
    await page.click('.save-zipcode');
    await page.reload();
    await page.waitForSelector('#PriceAdvisorFrame');

    const data = await page.evaluate(() => [
    ...document.querySelector('#PriceAdvisorFrame')
    .contentDocument.querySelectorAll('g#RangeBox text')
    ].map(elem => elem.textContent));

    console.log(data);

    await browser.close();
    // await browser.close();
    } catch (err) {
    console.error(err);
    }
  4. vsemozhetbyt created this gist Mar 18, 2019.
    22 changes: 22 additions & 0 deletions puppeteer-kbb.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    'use strict';

    const puppeteer = require('puppeteer');

    (async function main() {
    try {
    const browser = await puppeteer.launch({ headless: false });
    const [page] = await browser.pages();

    await page.goto('https://www.kbb.com/mini/countryman/2013/cooper-s-hatchback-4d/?intent=buy-used&pricetype=private-party&mileage=34000');

    const data = await page.evaluate(() =>
    [...document.querySelectorAll('div.price')].map(elem => elem.innerText)
    );

    console.log(data);

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