Added parsing for vins
parent
f52cd359ae
commit
9bc932a90b
File diff suppressed because it is too large
Load Diff
@ -1,11 +1,21 @@
|
|||||||
const genericBootstrapFactory = require("./generic-bootstrap")
|
const genericBootstrapFactory = require("./generic-bootstrap");
|
||||||
|
const genericVinParserFactory = require("./generic-vin-parser");
|
||||||
|
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
execute: genericBootstrapFactory({
|
execute: genericBootstrapFactory({
|
||||||
baseUrl: 'classiccars.com',
|
baseUrl: 'classiccars.com',
|
||||||
pageLoadIndicator: '#ListingCarousel',
|
pageLoadIndicator: '#ListingCarousel',
|
||||||
vinSelector: 'li.p-vin > span:nth-child(2)',
|
vinSelector: 'li.p-vin > span:nth-child(2)',
|
||||||
carouselTrigger: 'div.swiper-slide-active > div > img.u-photo'
|
carouselTrigger: 'div.swiper-slide-active > div > img.u-photo'
|
||||||
}),
|
}),
|
||||||
baseUrl :'classiccars.com'
|
baseUrl: 'classiccars.com',
|
||||||
|
parseVIN: genericVinParserFactory({
|
||||||
|
vinElementSelector: `li.border-btm.p-vin span.w40.d-inline-block.b.fs-14.gray`
|
||||||
|
}),
|
||||||
|
parseMileage: async function (page) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//li.border-btm.p-vin span.w40.d-inline-block.b.fs-14.gray
|
||||||
}
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
const _ = require('lodash');
|
||||||
|
module.exports = function(config) {
|
||||||
|
return async function (page) {
|
||||||
|
const vinSelector = config.vinElementSelector;
|
||||||
|
const vinRegex = /(?<vin>A\d\w\d{3}\w\d{6})/i;
|
||||||
|
const possibleVinElements = await page.$$(vinSelector);
|
||||||
|
const evaluatedVinElements = await Promise.all(possibleVinElements.map(async element => await page.evaluate(el => el.textContent, element)));
|
||||||
|
const correctElement = _.find(evaluatedVinElements, element => vinRegex.test(element));
|
||||||
|
|
||||||
|
return correctElement ? vinRegex.exec(correctElement).groups.vin : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue