GuruEdzus Posted May 25, 2023 Report Share Posted May 25, 2023 Sveiki visiem. Vēlētos uzzināt, kā es varētu parsot citu lapu, lai iegūtu citas lapas contentu? Vēlams būtu ar javascript. Izmēģināju visādus variantus kā parsot, bet visu laiku met vienu un to pašu erroru. Access to fetch at '' from origin '' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. GET https://lapa.lv net::ERR_FAILED Uncaught (in promise) TypeError: Failed to fetch at <anonymous>:1:1 Ir kādam kādas idejas kā tomēr es varētu dabūt konkrētas lapas html dom? Precizējums - Vajadzētu tikai konkrētu elementu izdabūt no lapas Paldies jau iepriekš :) Quote Link to comment Share on other sites More sharing options...
briedis Posted June 4, 2023 Report Share Posted June 4, 2023 Nestrādās no pārlūka, ja vien tā lapa, kuru fetcho, to speciāli neatļaus (ar CORS headeri). Tas notiek tāpēc, pārlūks mēgīna pasargā tā lietotāju no "launiem" pieprasījumiem. Palasi: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS Quote Link to comment Share on other sites More sharing options...
You Posted July 24, 2023 Report Share Posted July 24, 2023 Vari lietot PHP lai fetčotu citas lapas saturu un to tālāk padot variablī frontendam. <?php $source = file_get_contents('https://www.tvnet.lv'); ?> <script type="text/javascript"> let tvnetSource = "<?php echo htmlspecialchars($source); ?>"; </script> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.