var beers = []; $('.beer-details').each(function(i, b) { b = $(b); var noLonger = 'This beer is no longer being produced by the brewery'; var beer = {}; beer['name'] = b.find('.name a').text().trim(); beer['style'] = b.find('.style').text().trim().replace(noLonger, '').split(' - '); beer['in_production'] = b.find('.style').text().indexOf(noLonger) == -1; beer['abv'] = parseFloat(b.next('.details').find('.abv').text()); beer['added'] = b.next('.details').find('.date').text().trim().replace('Added ', '').split('/').map(t => parseInt(t, 10)); beer['rating'] = parseFloat(b.next('.details').find('.num').text().replace('(', '').replace(')','')); beer['ratings'] = parseInt(b.next('.details').find('.raters').text().replace(',','')); beers.push(beer); }); var data = JSON.stringify(beers); var blob = new Blob([data], { type: 'text/json' }), e = document.createEvent('MouseEvents'), a = document.createElement('a'); a.download = location.href.split('/')[3] +'.json'; a.href = window.URL.createObjectURL(blob); a.dataset.downloadurl = ['text/json', a.download, a.href].join(':'); e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); a.dispatchEvent(e);