async function scrapeWeaponPage(url, wear, type) {
  console.log(`Scraping weapon at ${url}`);

  // Load page into Cheerio
  const html = await _getHtml(url);
  const $ = cheerio.load(html);

  // Find all prices for the weapon
  const weaponPrices = $('div#prices')
    .children('div .btn-group-sm.btn-group-justified:not(.price-bottom-space)')
    .children('a')
    .toArray()
    .map((result) => {
      return $(result)
        .children('span')
        .toArray()
        .map((x) => $(x).text());
    });

  // Find price of specific weapon
  const weaponPriceArray = weaponPrices.find(
    (price) =>
      (type.statTrak && price.includes('StatTrak') && price.includes(wear)) ||
      (type.souvenir && price.includes('Souvenir') && price.includes(wear)) ||
      (!type.statTrak &&
        !type.souvenir &&
        !price.includes('StatTrak') &&
        !price.includes('Souvenir') &&
        price.includes(wear))
  );
  const weaponPrice = weaponPriceArray ? weaponPriceArray.pop() : "Couldn't find price";

  return { price: weaponPrice };
}
/**
 * Extract data about the weapon at the provided URL.
 * @param {string} url - URL to scrape
 * @param {string} wear - wear of the weapon
 * @param {Object} type - object type
 * @param {boolean} [type.statTrak] - indicates if the details should be for a StatTrak weapon
 * @param {boolean} [type.souvenir] - indicates if the details should be for a souvenir weapon
 * @returns {Promise<import('../typedefs/container').WeaponDetailsData>}
 */
Extract data about the weapon at the provided URL.
Extract data about the weapon at the provided URL .
async function scrapeWeaponPage(url, wear, type) {
  console.log(`Scraping weapon at ${url}`);
  const html = await _getHtml(url);
  const $ = cheerio.load(html);
  const weaponPrices = $('div#prices')
    .children('div .btn-group-sm.btn-group-justified:not(.price-bottom-space)')
    .children('a')
    .toArray()
    .map((result) => {
      return $(result)
        .children('span')
        .toArray()
        .map((x) => $(x).text());
    });
  const weaponPriceArray = weaponPrices.find(
    (price) =>
      (type.statTrak && price.includes('StatTrak') && price.includes(wear)) ||
      (type.souvenir && price.includes('Souvenir') && price.includes(wear)) ||
      (!type.statTrak &&
        !type.souvenir &&
        !price.includes('StatTrak') &&
        !price.includes('Souvenir') &&
        price.includes(wear))
  );
  const weaponPrice = weaponPriceArray ? weaponPriceArray.pop() : "Couldn't find price";
  return { price: weaponPrice };
}
async function scrapeWeaponPage ( url , wear , type ) { console . log ( ` ${ url } ` ) ; const html = await _getHtml ( url ) ; const $ = cheerio . load ( html ) ; const weaponPrices = $ ( 'div#prices' ) . children ( 'div .btn-group-sm.btn-group-justified:not(.price-bottom-space)' ) . children ( 'a' ) . toArray ( ) . map ( ( result ) => { return $ ( result ) . children ( 'span' ) . toArray ( ) . map ( ( x ) => $ ( x ) . text ( ) ) ; } ) ; const weaponPriceArray = weaponPrices . find ( ( price ) => ( type . statTrak && price . includes ( 'StatTrak' ) && price . includes ( wear ) ) || ( type . souvenir && price . includes ( 'Souvenir' ) && price . includes ( wear ) ) || ( ! type . statTrak && ! type . souvenir && ! price . includes ( 'StatTrak' ) && ! price . includes ( 'Souvenir' ) && price . includes ( wear ) ) ) ; const weaponPrice = weaponPriceArray ? weaponPriceArray . pop ( ) : "Couldn't find price" ; return { price : weaponPrice } ; }
Extract data about the weapon at the provided URL.
Extract data about the weapon at the provided URL .
// Load page into Cheerio // Find all prices for the weapon // Find price of specific weapon