Published
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.
Learn more