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

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

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 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!