Skip to content

Commit db0107c

Browse files
committed
handling errors scrapping auctions
1 parent 1d94d3c commit db0107c

File tree

1 file changed

+76
-68
lines changed

1 file changed

+76
-68
lines changed

auction.js

+76-68
Original file line numberDiff line numberDiff line change
@@ -90,83 +90,88 @@ export async function collectAuctions() {
9090
}
9191

9292
const getCarModel = async (auctionId, page) => {
93-
await page.goto(`https://app.acvauctions.com/auction/${auctionId}`);
94-
95-
const propertiesToSave = [
96-
'city',
97-
'vin',
98-
'odometer',
99-
'auction id',
100-
'auction date',
101-
'make',
102-
'model',
103-
'year',
104-
'color',
105-
];
106-
107-
let carModel = {};
108-
109-
const title = page.locator('.vehicle-header-summary__name');
110-
await title.waitFor({
111-
state: 'visible',
112-
});
93+
try {
94+
await page.goto(`https://app.acvauctions.com/auction/${auctionId}`);
95+
96+
const propertiesToSave = [
97+
'city',
98+
'vin',
99+
'odometer',
100+
'auction id',
101+
'auction date',
102+
'make',
103+
'model',
104+
'year',
105+
'color',
106+
];
107+
108+
let carModel = {};
109+
110+
const title = page.locator('.vehicle-header-summary__name');
111+
await title.waitFor({
112+
state: 'visible',
113+
});
113114

114-
carModel.title = await title.innerText();
115+
carModel.title = await title.innerText();
115116

116-
carModel.condition = [];
117+
carModel.condition = [];
117118

118-
const condition = await page.locator('.condition-report');
119-
const isInoperable = await condition.getByText(
120-
/vehicle inop \(does not move\)/i
121-
);
119+
const condition = await page.locator('.condition-report');
120+
const isInoperable = await condition.getByText(
121+
/vehicle inop \(does not move\)/i
122+
);
122123

123-
if ((await isInoperable.count()) === 1) {
124-
carModel.condition.push('isInoperable');
125-
}
124+
if ((await isInoperable.count()) === 1) {
125+
carModel.condition.push('isInoperable');
126+
}
126127

127-
const doesNotStart = await condition.getByText(
128-
/engine cranks\, does not start/i
129-
);
128+
const doesNotStart = await condition.getByText(
129+
/engine cranks\, does not start/i
130+
);
130131

131-
if ((await doesNotStart.count()) === 1) {
132-
carModel.condition.push('doesNotStart');
133-
}
132+
if ((await doesNotStart.count()) === 1) {
133+
carModel.condition.push('doesNotStart');
134+
}
135+
136+
const price = await page.locator('.price').first();
137+
carModel.price = parseInt(
138+
(await price.innerText()).replace('$', '').replace(',', '')
139+
);
134140

135-
const price = await page.locator('.price').first();
136-
carModel.price = parseInt(
137-
(await price.innerText()).replace('$', '').replace(',', '')
138-
);
139-
140-
const details = await page.locator('.auction-vehicle-details');
141-
142-
const tableRows = await details.locator('tr').all();
143-
144-
for (const row of tableRows) {
145-
const label = (await row.locator('.left').innerText()).toLowerCase();
146-
const value = await row.locator('.right').innerText();
147-
148-
if (propertiesToSave.includes(label)) {
149-
if (label === 'odometer') {
150-
carModel[label] = {
151-
type: 'miles',
152-
value:
153-
value === 'True Mileage Unknown'
154-
? -1
155-
: parseInt(value.replace(',', '')),
156-
};
157-
} else if (label === 'year') {
158-
carModel[label] = parseInt(value);
159-
} else if (label === 'auction date') {
160-
carModel.auctionDate = value;
161-
} else if (label === 'auction id') {
162-
carModel.auctionId = parseInt(value);
163-
} else {
164-
carModel[label] = value;
141+
const details = await page.locator('.auction-vehicle-details');
142+
143+
const tableRows = await details.locator('tr').all();
144+
145+
for (const row of tableRows) {
146+
const label = (await row.locator('.left').innerText()).toLowerCase();
147+
const value = await row.locator('.right').innerText();
148+
149+
if (propertiesToSave.includes(label)) {
150+
if (label === 'odometer') {
151+
carModel[label] = {
152+
type: 'miles',
153+
value:
154+
value === 'True Mileage Unknown'
155+
? -1
156+
: parseInt(value.replace(',', '')),
157+
};
158+
} else if (label === 'year') {
159+
carModel[label] = parseInt(value);
160+
} else if (label === 'auction date') {
161+
carModel.auctionDate = value;
162+
} else if (label === 'auction id') {
163+
carModel.auctionId = parseInt(value);
164+
} else {
165+
carModel[label] = value;
166+
}
165167
}
166168
}
167-
}
168169

169-
return carModel;
170+
return carModel;
171+
} catch (e) {
172+
console.log(e);
173+
return null;
174+
}
170175
};
171176

172177
export async function scrapAuctions(auctionIds) {
@@ -203,7 +208,10 @@ export async function scrapAuctions(auctionIds) {
203208
// if (cars.length === 35) break;
204209

205210
const car = await getCarModel(auctionId, page);
206-
cars.push(car);
211+
212+
if (car) {
213+
cars.push(car);
214+
}
207215
}
208216

209217
const result = cars.filter((car) => {

0 commit comments

Comments
 (0)