Skip to content

Instantly share code, notes, and snippets.

@pezon
Last active May 3, 2019 16:00
Show Gist options
  • Save pezon/384d4c9d31a6a9449428 to your computer and use it in GitHub Desktop.
Save pezon/384d4c9d31a6a9449428 to your computer and use it in GitHub Desktop.
scrape namecheap domains to a spreadsheet

LAZY AF

  • Step 1. Load console-save.js
  • Step 2. Load namecheap-cart-scraper.js
  • Step 3. Convert with https://json-csv.com/
  • Step 4. Load to Google Spreadsheet
// thanks to this guy:
// http://www.declancook.com/save-json-file-from-chrome-developer-tools/
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
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)
}
})(console)
var $cartItem,
name,
price,
options = [];
function processGroup() {
var $cartItem = $(this).first('div.cart-item > div');
var name = $cartItem.find('strong')[0].nextSibling.data.replace(/\s+/g, '');
var price = parseFloat($cartItem.find('div.price > span.amount')[0].innerText.substring(1));
options.push({
name: name,
price: price
})
}
function sortOptions(a, b) {
return a.price - b.price;
}
function toCSV(obj) {
console.log(obj.name, ',', obj.price);
}
$('div.product-group').each(processGroup);
options.sort(sortOptions);
options.forEach(toCSV);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment