@@ -90,83 +90,88 @@ export async function collectAuctions() {
90
90
}
91
91
92
92
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
+ } ) ;
113
114
114
- carModel . title = await title . innerText ( ) ;
115
+ carModel . title = await title . innerText ( ) ;
115
116
116
- carModel . condition = [ ] ;
117
+ carModel . condition = [ ] ;
117
118
118
- const condition = await page . locator ( '.condition-report' ) ;
119
- const isInoperable = await condition . getByText (
120
- / v e h i c l e i n o p \( d o e s n o t m o v e \) / i
121
- ) ;
119
+ const condition = await page . locator ( '.condition-report' ) ;
120
+ const isInoperable = await condition . getByText (
121
+ / v e h i c l e i n o p \( d o e s n o t m o v e \) / i
122
+ ) ;
122
123
123
- if ( ( await isInoperable . count ( ) ) === 1 ) {
124
- carModel . condition . push ( 'isInoperable' ) ;
125
- }
124
+ if ( ( await isInoperable . count ( ) ) === 1 ) {
125
+ carModel . condition . push ( 'isInoperable' ) ;
126
+ }
126
127
127
- const doesNotStart = await condition . getByText (
128
- / e n g i n e c r a n k s \, d o e s n o t s t a r t / i
129
- ) ;
128
+ const doesNotStart = await condition . getByText (
129
+ / e n g i n e c r a n k s \, d o e s n o t s t a r t / i
130
+ ) ;
130
131
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
+ ) ;
134
140
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
+ }
165
167
}
166
168
}
167
- }
168
169
169
- return carModel ;
170
+ return carModel ;
171
+ } catch ( e ) {
172
+ console . log ( e ) ;
173
+ return null ;
174
+ }
170
175
} ;
171
176
172
177
export async function scrapAuctions ( auctionIds ) {
@@ -203,7 +208,10 @@ export async function scrapAuctions(auctionIds) {
203
208
// if (cars.length === 35) break;
204
209
205
210
const car = await getCarModel ( auctionId , page ) ;
206
- cars . push ( car ) ;
211
+
212
+ if ( car ) {
213
+ cars . push ( car ) ;
214
+ }
207
215
}
208
216
209
217
const result = cars . filter ( ( car ) => {
0 commit comments