Last active
March 22, 2019 02:16
-
-
Save vsemozhetbyt/20469874edba6f1e3fe933e773c32786 to your computer and use it in GitHub Desktop.
puppeteer for kbb.com
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({ 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); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: