Skip to content

Instantly share code, notes, and snippets.

@timgws
Last active January 27, 2016 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timgws/50e1fa9da5781f9c5c6a to your computer and use it in GitHub Desktop.
Save timgws/50e1fa9da5781f9c5c6a to your computer and use it in GitHub Desktop.
Getting Top 20 Books from Amazon as JSON for test data

Sometimes, I just want to generate a bunch of test data.

fzaninotto/Faker is awesome for generating fake data, but when you want something that is more real, such as book titles, how do you do it? I use my two favourite tools: Amazon... and Google Chrome :)

1: Go to http://www.amazon.com/best-sellers-books-Amazon/zgbs/books

2: Run the following inside the Google Chrome Developer Console:

books = [];
$('.zg_itemWrapper').each(function() {
  books.push({
    title: $(this).find('.zg_title').text().trim(),
    author: $(this).find('.zg_byline').text().trim().replace(/^by /, ''),
    link: $(this).find('a:first').attr('href').trim().replace(/\/ref=.*/, '')
  });
} )

3: Copy and paste the JSON from

JSON.stringify(books)

4: ???

5: PROFIT!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment