Published
Edited
Nov 12, 2020
2 stars
Insert cell
Insert cell
data = {
let opts = {'Api-User-Agent': 'wtf_wikipedia example'}
//fetch the page from the API
let doc = await wtf.fetch('List of Apollo astronauts', opts)

//grab the first table
let s = doc.sections('Apollo astronauts who walked on the Moon')
let list = s.tables()[0].json()

//grab the second table
s = doc.sections('Apollo astronauts who flew to the Moon without landing')
let list2 = s.tables()[0].json()

//combine them together
list = list.concat(list2)

//grab the data we want
let data = list.map(row => {
let result = {
name: '',
mission: ''
}
console.log(row)
if (row.Name) {
result.name = row.Name.text
//get the actual wikipedia page..
if (row.links) {
result.name = row.links[0].page
}
}
//get their mission(s)
if (row.Mission) {
result.mission = row.Mission.text
}
return result
})
return data
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more