Skip to content

Instantly share code, notes, and snippets.

@hayatibis
Last active October 19, 2023 07:28
Show Gist options
  • Save hayatibis/f58c73b00522f1405d8caef4eed770a7 to your computer and use it in GitHub Desktop.
Save hayatibis/f58c73b00522f1405d8caef4eed770a7 to your computer and use it in GitHub Desktop.
Average Price
var selector = '#searchResultsTable > tbody > tr > td.searchResultsPriceValue > div > span'
var elements = document.querySelectorAll(selector)
var totalPrice = 0;
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
var priceText = element.textContent || '';
var price = parseInt(priceText.replace('TL', '').replace('.', '').trim(), 10);
if (!isNaN(price)) {
totalPrice += price;
}
}
var totalElements = elements.length;
var averagePrice = totalPrice / totalElements;
averagePrice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment