Skip to content

Commit

Permalink
orpi
Browse files Browse the repository at this point in the history
  • Loading branch information
aymericdo committed Jan 27, 2024
1 parent cf1a055 commit ede0a73
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
5 changes: 1 addition & 4 deletions src/interfaces/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,15 @@ export interface OrpiMapping {
id: string
charges: string
cityLabel: string
coord: Coordinate
description: string
dpe: string | null
furnished: boolean
hasCharges: boolean
price: number
postalCode: string
price: string
renter: string
rooms: number
surface: number
title: string
yearBuilt: number
}

export interface PapMapping {
Expand Down
58 changes: 32 additions & 26 deletions src/services/websites/orpi/orpi.scrapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ export class OrpiScrapping {
virtualConsole: virtualConsole(),
}).window

const dataDOM = document.querySelector('[data-component=estate-bookmark]')

if (!dataDOM) return null

const dataElement = JSON.parse((dataDOM as unknown as { dataset: { tmAction: string } }).dataset.tmAction)
const description = document.querySelector('div.o-container > p')
const titleElement = document.querySelector('body > main > article > div > div > div > div > div > div > div > div > div > h1')
const descriptionElement = document.querySelector('div.o-container div.c-preview')
const chargesElement = Array.from(
document.querySelectorAll('.o-grid > .o-grid__col .u-list-unstyled.u-text-xs > li')
)
const cityElement = document.querySelector('body > main > article > div > div > div > div > div > div > div > div > div > h1 > span > span')
const priceElement = document.querySelector('body > main > article p > span')
const charges = chargesElement.find((element) => element.textContent.search('Provisions pour charges') !== -1)
const hasChargesElement = document.querySelector('p.u-mt-n > span.u-h1')
const hasCharges =
hasChargesElement &&
hasChargesElement.parentNode &&
hasChargesElement.parentNode.textContent.includes('charges comprises')
const hasCharges = hasChargesElement?.parentNode?.textContent?.includes('charges comprises')
const renter = document.querySelector('body > main > article > section > div > div > div > div > div > div > div > h3')

const dpe = document.querySelector('li.c-dpe__index--active')
const dpeRegex = /([A-Z])/g
Expand All @@ -33,25 +29,35 @@ export class OrpiScrapping {
dpeText = dpe.textContent.replace(dpeRegex, ' $1').trim()
}

const features = document.querySelectorAll('#collapse-details > div ul.o-grid li')

let furnished = false
let surface = null
let rooms = null

features.forEach((feature) => {
if (feature.textContent.match(/m²/g) && !feature.textContent.toLowerCase().includes('balcon')) {
surface = feature
} else if (feature.textContent.match(/pièce/g)) {
rooms = feature
} else if (feature.textContent.match(/Meublé/g)) {
furnished = true
}
})

return {
id: dataElement.prdref,
cityLabel: dataElement.nomVille,
coord: {
lng: dataElement.longitude,
lat: dataElement.latitude,
},
charges: charges && charges.textContent,
id: null,
cityLabel: cityElement?.textContent,
charges: charges?.textContent,
hasCharges,
description: description && description.textContent,
description: descriptionElement?.textContent,
dpe: dpeText ?? null,
furnished: !!dataElement.meuble,
postalCode: dataElement.codePostal,
price: dataElement.prdamount,
renter: dataElement.agenceNom,
rooms: dataElement.nbPieces,
surface: dataElement.surfaceBien,
title: dataElement.prdname.replace(/-/g, ' '),
yearBuilt: dataElement.anneeConstruction,
furnished: furnished,
price: priceElement?.textContent,
renter: renter?.textContent,
rooms: rooms?.textContent,
surface: surface?.textContent,
title: titleElement?.textContent,
}
}
}

0 comments on commit ede0a73

Please sign in to comment.