You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ListingExtractor/processors/superstockamx.processor.js

46 lines
1.6 KiB
JavaScript

const genericVinParserFactory = require("./generics/generic-vin-parser");
const {log} = require('clew-logger');
module.exports = {
baseUrl: 'superstockamx.com',
async execute(page) {
const gallerySelector = '.main-bg'
const imageSelector = 'img';
await page.waitForSelector(gallerySelector);
const images = await page.$$(imageSelector);
const sources = await Promise.all(images.map(async carouselItem => {
const src = await page.evaluate(el => el.getAttribute('src'), carouselItem);
if(src.includes('base64')) {
//base 64 pasted image
log.info('Found base64 image.')
const regex = /^data:(?<contentType>[^;]+);base64,(?<data>.+)/g;
const matches = src.matchAll(regex);
const groups = Array.from(matches, m => m.groups)[0]
return {base64: groups.data,
contentType: groups.contentType !== '<' ? groups.contentType : 'image/jpeg'};
} else if(src.startsWith('http')) {
return { url: src };
} else {
return {}
// anything hosted seperately on his site is not an actual car pic
// return {
// url: module.exports.baseUrl + '/' + src
// }
}
}));
return sources;
},
parseVIN: async function (page) {
return null;
},
parseMileage: async function (page) {
return null;
}
}