Skip to content

Instantly share code, notes, and snippets.

@lolmaus
Created October 20, 2022 11:04
Show Gist options
  • Save lolmaus/baa2c7ff5d93f59862e4e478782fb255 to your computer and use it in GitHub Desktop.
Save lolmaus/baa2c7ff5d93f59862e4e478782fb255 to your computer and use it in GitHub Desktop.
Regard.ru HDD price/size parser
console.log(Array.from(document.querySelectorAll('.Card_row__3FoSA')).map(parent => {
const titleRaw = parent.querySelector('h6').textContent;
const price = parseInt(parent.querySelector('.Card_price__2Q9vg').textContent.replaceAll(/(?!\d)./g, ''), 10);
const [,sizeStr,unit,title] = titleRaw.match(/Жёсткий диск\s+(\d+)(\S+)\s+(?:\S+)\s+(.+)/);
const sizeUnknown = parseInt(sizeStr, 10);
const sizeGb = unit === 'Gb' ? sizeUnknown : sizeUnknown * 1000;
return {
title,
price,
sizeGb,
}
}).map(({title, price, sizeGb}) => `${title},${price},${sizeGb}`).join("\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment