Platform
Resources
Pricing
Sign in
Contact us
Ian Lyttle
Workspace
Fork
Public
By
Ian Lyttle
Edited
Jul 16, 2023
Fork of
Wikipedia: Most-Populous Cities
2
Insert cell
Insert cell
Insert cell
// fecthed 2023-07-15
// fetch(`https://en.wikipedia.org/w/api.php?format=json&origin=*&action=parse&prop=text&page=List_of_largest_cities§ion=5`).then((response) => response.json())
Insert cell
Insert cell
listLargestCities
=
FileAttachment
(
"list-largest-cities_2023-07-15.json"
)
.
json
(
)
Insert cell
Insert cell
Insert cell
Insert cell
table
.
querySelector
(
"tbody tr:nth-child(4)"
)
.
cloneNode
(
true
)
Insert cell
Insert cell
rowsHtml
=
table
.
querySelectorAll
(
"tbody tr:nth-child(n+4)"
)
Insert cell
Insert cell
rowsData
=
Array
.
from
(
rowsHtml
,
(
r
)
=>
(
{
name
:
r
.
querySelector
(
"th a"
)
.
textContent
.
trim
(
)
,
title
:
r
.
querySelector
(
"th a"
)
.
getAttribute
(
"href"
)
.
trim
(
)
.
replace
(
/^.*\//
,
""
)
}
)
)
Insert cell
Insert cell
Inputs
.
table
(
rowsData
)
Insert cell
Insert cell
Insert cell
getWikiExtract
=
async
function
(
name
)
{
const
json
=
await
fetch
(
`https://en.wikipedia.org/w/api.php?format=json&origin=*&action=query&prop=text§ion=0&redirects=1&titles=${
name
}`
)
.
then
(
(
response
)
=>
response
.
json
(
)
)
;
return
json
;
}
Insert cell
// uncomment to test for yourself:
await
getWikiExtract
(
"Johannesburg"
)
Insert cell
getWikiExtract2
=
async
function
(
name
)
{
const
json
=
await
fetch
(
`https://en.wikipedia.org/api/rest_v1/page/summary/${
name
}`
)
.
then
(
(
response
)
=>
response
.
json
(
)
)
;
return
json
;
}
Insert cell
{
const
temp
=
await
getWikiExtract2
(
"London"
)
;
return
md
`${
temp
.
extract
}`
;
}
Insert cell
Insert cell
// fetched 2023-07-15
// cityLabelText = Promise.all(
// rowsData.map(async (x) => ({
// label: x.name,
// text: await getWikiExtract(x.title)
// }))
// )
Insert cell
Insert cell
cityLabelText
=
FileAttachment
(
"city-label-text_2023-07-15.json"
)
.
json
(
)
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.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
listLargestCities
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
table
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
rowsHtml
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
rowsData
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getWikiExtract
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getWikiExtract2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cityLabelText
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML