Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
¿Cómo puedo obtener los datos JSON entre las etiquetas de script?

Quiero buscar una página html y luego analizarla con domParser. luego quiero extraer la matriz entre las etiquetas de script dentro de este archivo html. ¿Cómo puedo acceder a imageUrl en la etiqueta del script dentro de este archivo html?

 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 answers
Answer question

0

El objeto definido en la etiqueta del script se inicializa inmediatamente. Todos los demás js que se inicializan o ejecutan más tarde tienen acceso al objeto definido.

 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); });

Compruebe ¿Cuál es el alcance global de la etiqueta <script>?

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!