Created
October 20, 2022 11:04
-
-
Save lolmaus/baa2c7ff5d93f59862e4e478782fb255 to your computer and use it in GitHub Desktop.
Regard.ru HDD price/size parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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