Platform
Resources
Pricing
Sign in
Get started
Ashish Singh
Data Visualization Consultant, and an enthusiastic generalist in building software systems
Workspace
Fork
Published
Fun
By
Ashish Singh
Edited
May 24, 2021
1 fork
1 star
Insert cell
Insert cell
url
=
`www.goodreads.com/choiceawards/best-historical-fiction-books-2020`
Insert cell
Inputs
.
table
(
books
)
Insert cell
books
=
{
const
books
=
[
]
;
// loop through books
GRBODY
.
selectAll
(
".inlineblock.pollAnswer.resultShown"
)
.
each
(
function
(
br
)
{
// get votes text
const
votes
=
d3
.
select
(
this
)
.
select
(
".uitext.result"
)
.
text
(
)
;
// add to an object
books
.
push
(
{
votes
:
votes
}
)
;
}
)
;
return
books
;
}
Insert cell
Insert cell
// Get the HTML BODY of the url as a d3 selection
GRBODY
=
d3
.
select
(
getSourceAsDOM
(
`${
corsbypass
}${
url
}`
)
.
body
)
Insert cell
corsbypass
=
`https://cors-anywhere-git-ashish.herokuapp.com/`
Insert cell
// Get DOM of a URL
function
getSourceAsDOM
(
url
)
{
const
xmlhttp
=
new
XMLHttpRequest
(
)
;
xmlhttp
.
open
(
"GET"
,
url
,
false
)
;
xmlhttp
.
send
(
)
;
const
parser
=
new
DOMParser
(
)
;
return
parser
.
parseFromString
(
xmlhttp
.
responseText
,
"text/html"
)
;
}
Insert cell
Insert cell
import
{
Inputs
}
from
"@observablehq/inputs"
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
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
url
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
books
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
GRBODY
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
corsbypass
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getSourceAsDOM
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML