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

101
Vistas
How can I get the JSON data between the script tags?

I want to fetch an html page and then parse it with domParser. then I want to pull the array between the script tags inside this html file. How can I access the imageUrl in the script tag inside this html file?

fetch(geturl)
           .then(function(response) {
               return response.text();
           })
           .then(function(html) {
               var parser = new DOMParser();
               var document = parser.parseFromString(html, "text/html");
               // here
           })
           .catch(function(error) {
               console.log("Error: ", error);
           });
<script>
let testArray = {"test":"138","test2":95,"imageUrl":"hrththterg122323"};
</script>
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The object defined in script tag gets initialized immediately. All other js that is initialized or run later has access to the defined object.

fetch(geturl)
       .then(function(response) {
           return response.text();
       })
       .then(function(html) {
           var parser = new DOMParser();
           var document = parser.parseFromString(html, "text/html");
           
           console.log(testArray.imageUrl);
       })
       .catch(function(error) {
           console.log("Error: ", error);
       });

Check What is the global scope of <script> tag?

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