Published
Edited
Dec 1, 2021
Insert cell
Insert cell
page = FileAttachment("https _en.wikipedia.org_wiki_Sea_otter.htm").text()
Insert cell
data = {
const $ = cheerio.load(page)
const paragraph = $("p").eq(1)
const links = paragraph.find("a")
const result = []
for(let i = 0; i < links.length; i = i + 1){
const text = links.eq(i).text()
const url = "https://en.wikipedia.org" + links.eq(i).attr("href")
result.push({text:text,url:url})
}
return result
}
Insert cell
table = {
let table = `<table>`
for(let i = 0; i < data.length; i = i + 1){
table = table + ` <tr> <td><a href = "${data[i].url}" >${data[i].text}</a></td> </tr> `
}
table = table + `</table>`
return table
}
Insert cell
html`${table}`
Insert cell
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
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