JSFiddle - React, Tailwind, and code Playground
by al nmeri
JavaScript
var mainRes = [],
limit = 3; // for debug
$('.RMAuctions.grid-item').slice(0, limit).each(function(i,el) {
var e = $(el),
priceSec = e.find('span.heading-subtitle--bold').text(),
getEstimate = function () {
const el = priceSec.match(/^[^a-z0-9](.+) - .(.+)/);
var est = {low: null, high: null}
if (el) {
est['low']= el[1];
est['high'] = el[2]
}
return est;
},
curTable = { "EUR": '€', "USD": '$', "GBP": '£'},
name = e.find('p.heading-subtitle--bold').text(),
sold = priceSec.contains('sold for') ? 'yes' : 'no',
high_estimates = !sold ? getEstimate().high: null,
obj = {
title: name,
date: parseInt(name),
sold: sold,
image_url: e.find('img.expanded-content').attr('src'),
low_estimates: !sold ? getEstimate().low: null,
high_estimates: high_estimates,
type: $('#ddlSearchByCategory').val() == 'Automobiles' ? 'car': 'motorbike',
url: 'https://www.rmsothebys.com' + e.children('a').attr('href'),
original_hammer_price_currency:
high_estimates ?
Object.keys(curTable).filter(function (e) { return this[e] == priceSec.substring(0,1)}, curTable)[0]:
null
},
getOtherFields = function (current, i) {
$.get(current.url).done(function (pageRes) {
console.log(current.url)
const page = $(pageRes);
var chas = page.find('.lot__specifications--right'),
sellDate = page.find('.lot__titles h3.heading-details--bolder').text(),
deadFields = ['hammer_price', 'original_hammer_price', 'engine_number', 'body_number',
'gearbox_number', 'case_material', 'dimensions', 'medium', 'colour'];
if (sellDate) {
sellDate = sellDate.substring(sellDate.indexOf('Offered on: '))
if (sellDate) {
current['date_of_sale'] = formatDate( sellDate)
current['year_of_sale'] = sellDate.substr(-4)
}
}
current['frame_number'] = current['type'] == 'car' ? null : page.find('.lot__specifications--left').text().contains('frame') ? chas.text().trim() :...