Skip to content

Instantly share code, notes, and snippets.

@WillsB3
Created March 27, 2016 19:08
Show Gist options
  • Save WillsB3/5c7d91403614a52ef4c3 to your computer and use it in GitHub Desktop.
Save WillsB3/5c7d91403614a52ef4c3 to your computer and use it in GitHub Desktop.
Chrome D
var parsedDeals = [];
var csv = '';
var dealRows = $('.table-row');
var fields = ['network', 'duration', 'monthly', 'upfront', 'data', 'mins', 'texts', 'cashback', 'url'];
fields.forEach(function(f, i, a) {
csv += f + '\t';
});
csv += '\n';
$.each(dealRows, function(idx, deal) {
var $d = $(deal);
var d = {};
var a;
var upfront = $d.find('[data-bind="html: handset_cost, visible: (handset_cost != \'FREE\')"]').eq(0).text();
if (upfront === 'FREE') {
upfront = '£0';
} else {
upfront = upfront.replace(' upfront', '');
}
d.network = $d.find('.table-image__network img').get(0).alt;
d.duration = $d.find('span[data-bind="html: contract_length"]').text().replace(' month', '');
d.monthly = $d.find('.monthly-cost__title').eq(0).text();
d.upfront = upfront;
d.data = $d.find('[data-bind="html: data"]').eq(0).text();
d.mins = $d.find('[data-bind="html: minutes"]').eq(0).text();
d.texts = $d.find('[data-bind="html: texts"]').eq(0).text();
a = $('<a>', { href: $d.find('a').attr('href') })[0];
d.url = a.href;
d.cashback = $d.find('span.cashback').not('.usp').text().replace(' cashback', '');
parsedDeals.push(d);
var csvRow = '';
fields.forEach(function(f, i, a) {
csvRow += d[f];
if (i < a.length - 1) {
csvRow += '\t';
}
});
csv += csvRow + '\n';
});
console.table(parsedDeals);
console.table(csv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment