Skip to content

Instantly share code, notes, and snippets.

@Narvey
Created April 14, 2020 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Narvey/cb96ce004d473c7d44104fc43d1055e5 to your computer and use it in GitHub Desktop.
Save Narvey/cb96ce004d473c7d44104fc43d1055e5 to your computer and use it in GitHub Desktop.
Parsing of our church directory (I used this in the js scratchpad, but console should work too)
contacts = []
;[...document.getElementsByClassName("household")].forEach(div=>
{
let names = [... div.getElementsByTagName("b")].map(e=>e.innerText)
let results = /(\w+)['’]s Cell ([-0-9]+)/.exec(div.innerText)
let surname = names[0]
if (surname.split(" ").length>1)//check for the unmarried
{
surname = surname.split(" ")[1] //grab surname
console.log(surname)
}
else surname = names[1].split(" ")[1]
if(!/^\w+$/.test(surname)) surname = names[0].split()
if(results)
contacts.push({
name: results[1] + " " + surname,
phone: results[2]
})
else
contacts.push({
name: surname,
phone: 0
})
})
contacts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment