Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
Cheerio returns empty string while scraping target.com

I am trying to scrape a product page of target.com to retrieve the product title, price and image using cheerio. Using the code below I was able to retrieve the title and image, but the price always returns an empty string. I am new to scraping and I have run out of my wits. Any help is appreciated.

Thank you!

const axios = require('axios')
const cheerio = require('cheerio');
const { html } = require('cheerio/lib/api/manipulation');
const express = require('express')
const { get } = require('http')

async function getTargetProductDetails(prodUrl) {
    try {
        const scrapeUrl = prodUrl

        const { data } = await axios({
            method: "GET",
            url: scrapeUrl,
            headers: {
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36",
            },
        })
        const $ = cheerio.load(data)
        const prodTitleElemSelector = '#pageBodyContainer > div:nth-child(2) > div.h-padding-h-default > h1 > span'
            
        const prodPriceElemSelector = '#pageBodyContainer > div:nth-child(2) > div.styles__StyledRow-sc-1nuqtm0-0.znNOo > div.styles__StyledCol-sc-ct8kx6-0.CBMCR.styles__StyledSecondCol-sc-y0ahq4-2.jftnqo.h-padding-h-default > div > div.h-margin-b-x2 > div:nth-child(1) > span'
        const imgElemSelector = '#pageBodyContainer > div:nth-child(2) > div.styles__StyledRow-sc-1nuqtm0-0.znNOo > div.styles__StyledCol-sc-ct8kx6-0.cQDVpz.styles__StyledFirstCol-sc-2vujr8-3.hHPFGX.h-padding-h-default > div:nth-child(1) > section > div.styles__CarouselProductFilmstripWrapper-sc-cwwbs3-2.fMvUGZ > div.styles__NicolletFilmstripDiv-sc-1ldzhqm-0.ctFgTt.BaseCarousel-sc-pnaqvl-0.loHErH > div > button:nth-child(1) > div > div > div > div'

        console.log($(prodTitleElemSelector).text().trim())
        console.log($(imgElemSelector).find('img').attr('src'))
        console.log($(prodPriceElemSelector).text())
        


    } catch (err) {
        console.error(err)
    }

}

getTargetProductDetails('https://www.target.com/p/nintendo-switch-lite/-/A-83031385?preselect=77419248#lnk=sametab')

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The data was actually being fetched via few APIs. Inspecting the page source revealed the json objects. Extracting the json data was all I had to do to get what I wanted.

Here is the exact solution !

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda