Skip to content

Instantly share code, notes, and snippets.

@vsemozhetbyt
Last active March 22, 2019 02:16
Show Gist options
  • Save vsemozhetbyt/20469874edba6f1e3fe933e773c32786 to your computer and use it in GitHub Desktop.
Save vsemozhetbyt/20469874edba6f1e3fe933e773c32786 to your computer and use it in GitHub Desktop.
puppeteer for kbb.com
'use strict';
const puppeteer = require('puppeteer');
(async function main() {
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');
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');
const data = await page.evaluate(() => [
...document.querySelector('#PriceAdvisorFrame')
.contentDocument.querySelectorAll('g#RangeBox text')
].map(elem => elem.textContent));
console.log(data);
await browser.close();
} catch (err) {
console.error(err);
}
})();
@vsemozhetbyt
Copy link
Author

vsemozhetbyt commented Mar 18, 2019

Output:

[ '$12,270',
  'Private Party Value',
  '$10,863 - $13,676',
  'Private Party Range' ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment