Skip to content

Instantly share code, notes, and snippets.

@joshparkerj
Created July 1, 2021 05:14
Show Gist options
  • Save joshparkerj/d4b7cbc083e75b13eeb7ad2a61104fd7 to your computer and use it in GitHub Desktop.
Save joshparkerj/d4b7cbc083e75b13eeb7ad2a61104fd7 to your computer and use it in GitHub Desktop.
Parse goodreads book list
// I used this at https://www.goodreads.com/series/40650-discworld
console.log(['title,author,rating,ratings,reviews,date,editions', ...[...document.querySelectorAll('.responsiveBook')].map((rb) => {
const title = rb.querySelector('.gr-h3 span[itemprop="name"]').textContent;
const author = rb.querySelector('span[itemprop="author"]').textContent;
const rating = rb.querySelector('.communityRating__starsWrapper ~ .gr-metaText').textContent;
const allTextContent = rb.textContent;
const matches = allTextContent.match(/(?<ratings>[\d,]+) Ratings[^\d\w]*((?<reviews>[\d,]+) Reviews)?[^\d\w]*(published (?<date>\d+))?[^\d\w]*((?<editions>\d+) editions)?/);
return {
title,
author,
rating,
...matches.groups,
};
}).map(({
title, author, rating, ratings, reviews, date, editions,
}) => `"${title}","${author}","${rating}","${ratings}","${reviews || 0}","${date || 'unknown'}","${editions || 1}"`)].join('\n'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment