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

295
Vistas
I need to get a script using cherrio (not get text)

I am scrapping a page and I need to get a json from a script tag the script tag seens like

<template data-type="json" data-varname="__STATE__"> 
<script>
{
 "someJson": here 
}
</script>    
</template>

I got the value with something like this using jquery in browser

 $('template[data-varname="__STATE__"]').content.children[0]

and i got the value with something like that on my node code

const listItems = await $('template[data-varname="__STATE__"]');
await fs.promises.writeFile('site.html', listItems.html())

but my return is only a script like this

   <script>
    {
     "someJson": here 
    }
    </script>  

inside a html file but I would like to get the json and already be able to use

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I got what I wanted as follows

const listItems = await $('template[data-varname="__STATE__"]');
const scriptItem = await  listItems.html()
const removeScript = scriptItem.replace("<script>","").replace("</script>","")
const jsonFromScript = JSON.parse(removeScript)

However this is not a solution that I like, if anyone knows a more "correct" way to do it I would be grateful

about 4 years ago · Juan Pablo Isaza 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