diff options
author | emkael <emkael@tlen.pl> | 2021-01-20 00:19:41 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2021-01-20 00:19:41 +0100 |
commit | 5857bc07aa4414d4ca14696fbcb9d31521bcfd1d (patch) | |
tree | c2873902a457a7c49f418cfb3e8fe820ffe020a5 /scrape.js | |
parent | 4aa41c8ad9b41ce15cfd9a2e533f1cc2e7ed3dbf (diff) |
Extended data
Diffstat (limited to 'scrape.js')
-rw-r--r-- | scrape.js | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -1 +1 @@ -var beers = []; $('.beer-details').each(function(i, b) { b = $(b); var beer = {}; beer['name'] = b.find('.name a').text().trim(); beer['style'] = b.find('.style').text().trim().replace('This beer is no longer being produced by the brewery', '').split(' - '); 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); }); console.log(JSON.stringify(beers)); +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); |