Skip to content

Commit

Permalink
improve collection auctions
Browse files Browse the repository at this point in the history
  • Loading branch information
xtatanx committed Jun 8, 2023
1 parent 84d2ca8 commit 1d94d3c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 40 deletions.
36 changes: 26 additions & 10 deletions auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ export async function collectAuctions() {

const filterToggle = page.locator('#saved-search-261859');
await filterToggle.waitFor({ state: 'attached' });
filterToggle.evaluate((node) => node.click());

await filterToggle.evaluate((node) => node.click());

const totalResultsText = await page
.locator('.result-number', {
hasNotText: '0 Results Total Match Your 1 Saved Search',
})
.innerText();

const total = parseInt(totalResultsText.split(' ')[0]);

const auctionIds = [];
let shouldCollect = true;
Expand All @@ -47,24 +56,31 @@ export async function collectAuctions() {
const responsePromise = page.waitForResponse(
'https://easy-pass.acvauctions.com/bff/filters/auctions/buying/ended'
);
const response = await responsePromise;

await page.evaluate(async () => {
window.scrollTo(0, document.body.scrollHeight);
});

const response = await responsePromise.catch(() => null);

if (!response) {
continue;
}

if (response.status() === 200) {
const {
data: { results },
} = await response.json();
console.log(results.length);

if (results.length !== 0) {
auctionIds.push(...results.map((result) => result.id));
await page.evaluate(async () => {
window.scrollTo(0, document.body.scrollHeight);
});
} else {
shouldCollect = false;
}
auctionIds.push(...results.map((result) => result.id));
} else {
shouldCollect = false;
}

if (auctionIds.length === total) {
shouldCollect = false;
}
}

await context.close();
Expand Down
40 changes: 18 additions & 22 deletions index-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,22 @@ import { proQuoteCar } from './proquote.js';
dotenv.config();

(async () => {
try {
// while (true) {
// await proQuoteCar({
// title: '2010 GMC Acadia SLE',
// condition: [],
// price: 1250,
// city: 'Peoria, IL',
// vin: '1GKLVLED9AJ101761',
// odometer: { type: 'miles', value: 146743 },
// year: 2010,
// make: 'GMC',
// model: 'Acadia',
// color: 'Silver',
// auctionId: 7304031,
// auctionDate: '6/2/2023',
// proQuote: { avg: 1296.71 },
// });
// }
await init();
} catch (e) {
console.log(e);
}
// while (true) {
// await proQuoteCar({
// title: '2010 GMC Acadia SLE',
// condition: [],
// price: 1250,
// city: 'Peoria, IL',
// vin: '1GKLVLED9AJ101761',
// odometer: { type: 'miles', value: 146743 },
// year: 2010,
// make: 'GMC',
// model: 'Acadia',
// color: 'Silver',
// auctionId: 7304031,
// auctionDate: '6/2/2023',
// proQuote: { avg: 1296.71 },
// });
// }
await init();
})();
10 changes: 2 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import { init } from './scrapper.js';
dotenv.config();

functions.http('initScrapping', async (_, res) => {
try {
await init();
res.send('done');
} catch (e) {
console.log('::: main catch :::');
console.log(e);
res.status(400).send(e);
}
await init();
res.send('done');
});

0 comments on commit 1d94d3c

Please sign in to comment.