1

im making a blog were i will show a product and all of it's prices on all the websites that sell this product, but i whant the prices to be up to date so i decided to make a webscrap script so i can allways get the updated product price, but it does not seem to work... i searched all over the internet and i didn't find anyone that can do this, can you guys help me fix my code? :D

 var dd = document.querySelectorAll("dd");
   
   var xhr = new XMLHttpRequest();

   xhr.open("GET","https://www.chewy.com/blue-buffalo-life-protection-formula/dp/32041")
   xhr.responseType = "document";

   xhr.onload = function(){
       if(xhr.readyState = 4 && xhr.status == 200)
       {
           var response = xhr.responseXML.querySelectorAll("#advertised-price")

           dd[0].innerText = response[1].children[1].textContent;
           
           console.log(response);
       }
   };

   xhr.onerror = function()
   {
       console.error(xhr.status, xhr.statusText);
   }

   xhr.send();

https://codepen.io/galusk0149007/pen/zYRoovY

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
GGalusca
  • 101
  • 5
  • `Access to XMLHttpRequest at 'https://www.chewy.com/blue-buffalo-life-protection-formula/dp/32041' from origin 'https://stackoverflow.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource` – GrafiCode May 13 '22 at 20:39
  • please see this: https://stackoverflow.com/questions/20035101/why-does-my-javascript-code-receive-a-no-access-control-allow-origin-header-i – GrafiCode May 13 '22 at 20:41

0 Answers0