Skip to content

Instantly share code, notes, and snippets.

@mcginty
Created September 27, 2018 12:14
Show Gist options
  • Save mcginty/9fb93af84a89035e90cebb44ce7d6c49 to your computer and use it in GitHub Desktop.
Save mcginty/9fb93af84a89035e90cebb44ce7d6c49 to your computer and use it in GitHub Desktop.
const puppeteer = require('puppeteer');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
(async () => {
const browser = await puppeteer.launch({headless: false});
// const browser = await puppeteer.launch();
let attempts = 0;
while (attempts < 3) {
console.log(`attempt ${attempts}`);
const page = await browser.newPage();
try {
console.log('goto');
await page.goto('https://www.copart.com/auctions/auctionDashboard', {waitUntil: 'networkidle'});
console.log('waitFor iframe');
await page.waitFor('#iAuction5');
console.log('found');
await page.waitFor(1000);
let childFrames = await page.mainFrame().childFrames();
if (childFrames.length != 1) {
console.log('hmm, child frame still not here...');
await page.waitFor(2000);
let childFrames = await page.mainFrame().childFrames();
if (childFrames.length != 1) {
throw new Error("missing child iframe, throwing error.");
}
}
const childFrame = childFrames[0];
console.log('child frame found, waiting for auction table to appear');
await childFrame.waitForSelector('.arAuctiontable');
console.log('got auction table');
try {
await childFrame.waitForSelector('button.arJoinBtn');
} catch (e) {
console.log("it doesn't look like there are any live auctions.");
await browser.close();
return;
}
const buttons = await childFrame.$('button.arJoinBtn');
consoel.log('buttons: ');
console.log(buttons);
// console.log(`${buttons.length} live auctions right now.`);
// if (buttons.length > 0) {
// await page.WaitFor(500);
// console.log("since there are live auctions, let's click one...");
// buttons.click({delay: 120});
// console.log("waiting for descriptions of cars in the lot...");
// await childFrame.waitForSelector('div.arDescription');
// const descriptions = await childFrame.$('button.arDescription');
// console.log(descriptions);
// }
await page.waitFor(1000);
await page.screenshot({path: 'screenshot.png'});
attempts = 1000;
} catch (e) {
console.error('error, retrying after a sec');
await page.close();
attempts += 1;
await sleep(1000);
}
}
await browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment