From a person's Profile page.
var siblings = {};
var family = {};
var parents = [];
[...document.querySelectorAll('.family_relative')].forEach(i => {
const relativeName = i.querySelector('.relative_name')?.textContent
const relationship = i.querySelector('.relative_relationship')?.textContent
const [ birth, death = null ] = i.querySelector('.relative_years').textContent.split('-').map(i => i.trim())
const isDead = death !== null
const relationshipString = relationship.replace(/(his|her) /i, '')
const isSibling = /(brother|sister)/i.test(relationshipString)
const isSpouse = /(husband|wife)/.test(relationship)
const isParent = /(mother|father)/.test(relationship)
const isChild = /(daughter|son)/.test(relationship)
let row = `${relativeName}`
let dates = []
if (Number.parseInt(birth)) {
dates.push(birth)
}
if (isDead) {
let d = ''
if (Number.parseInt(death)) {
d += `deceased ${death}`;
} else {
d += `deceased`;
}
if (d !== '') {
dates.push(d)
}
}
if(dates.length >= 1) {
row += ' (' + dates.join(', ') + ')'
}
if (isSibling) {
const s = Reflect.get(siblings, relationshipString) ?? []
s.push(row)
Reflect.set(siblings, relationshipString, s)
} else if (isChild) {
const s = Reflect.get(family, relationshipString) ?? []
s.push(row)
Reflect.set(family, relationshipString, s)
} else if (isSpouse) {
const s = Reflect.get(family, 'spouse') ?? []
s.push(row)
Reflect.set(family, 'spouse', s)
} else if (isParent) {
const deathText = (death === null) ? '~' : death
const parent = {
name: relativeName,
birth,
birthplace: "~",
death: deathText,
deathplace: "~",
parents: [],
}
parents.push(parent)
}
console.log({row, relativeName, relationshipString, relationship, birth, death, isDead, isSibling, isSpouse, isParent })
})
copy({family, siblings, parents})
Example output
family:
spouse:
- 'Delina Marie Chauvette (1880, deceased 1939)'
son:
- 'Joseph Alfred Boulanger (1900, deceased 1905)'
- 'Alphonse Boulanger (1902, deceased 1970)'
- 'Oscar Henri Boulanger (1905, deceased 1970)'
- 'Alfred Louis Boulanger (1910, deceased)'
- 'Omer Boulanger (1920, deceased)'
daughter:
- 'Marie Rosina Boulanger (1903, deceased 1978)'
- 'Rose Eva Boulanger (1909, deceased)'
- 'Dorilla Boulanger (1912, deceased 1998)'
- 'Rose Aimée Boulanger (1917, deceased 1997)'
- Demerise Rose Eva Boulanger
siblings:
sister:
- 'Rosina Rose Anna Marie Boulanger (1877, deceased 1962)'
- 'Emma Claudia Boulanger (1883, deceased 1921)'
- 'Louise Anna Boulanger (1885, deceased 1973)'
- 'Philomene Boulanger (1892, deceased 1982)'
- 'Josephine Flora Boulanger (1893, deceased 1934)'
- 'Demerise Boulanger (1896, deceased 1922)'
- Virginia Marie Boulanger
brother:
- 'Alfred Adelard Boulanger (1882, deceased)'
- 'Anonyme Boulanger (1887, deceased 1887)'
- 'Henri Honore Boulanger (1888, deceased 1945)'
- 'Napoleon Josephat Adelard Boulanger (1891, deceased 1891)'
This looks interesting, can you give some context?!