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