0

I want to read data from a webpage and i followed below

$(document).ready(function() {
  function url_content2(url) {
    $.get(url)
  }
  var url2 = "https://javascript.info/?url=" + encodeURIComponent("https://www.psacard.com/cert/27333489/") + '&callback=?';

  url_content2(url2, function(data) {
    console.log(data);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Taken references from Can Javascript read the source of any web page?

Cross-Origin Read Blocking (CORB)

How to stop CORB from blocking requests to data resources that respond with CORS headers? and

https://www.freecodecamp.org/news/client-side-web-scraping-with-javascript-using-jquery-and-regex-5b57a271cb86/

But In my case none of one worked

Might be the reason becuase it is not directly accesible check image Please help to get the webpage data

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
cakePHP
  • 425
  • 1
  • 4
  • 23
  • 1
    You cannot make client side JS requests to third party domains which expressly permit it by including CORS headers in the response. The domain you're calling does not do this, so you cannot call it as you're attempting to. You'll need to make the request server side instead In fact, the 'Don't let CORS stop you' section of the links you reference covers this: https://www.freecodecamp.org/news/client-side-web-scraping-with-javascript-using-jquery-and-regex-5b57a271cb86/#don-t-let-cors-stop-you- – Rory McCrossan May 29 '20 at 11:16
  • @RoryMcCrossan there is the code var name = "codemzy";var url = "http://anyorigin.com/go?url=" + encodeURIComponent("https://www.codewars.com/users/") + name + "&callback=?";$.get(url, function(response) { console.log(response);}); which tell you can fetch data by some other domin callback. – cakePHP May 29 '20 at 11:26
  • Right, but you cannot call the `javascript.info` domain as it returns no CORS headers, hence my first comment. I've edited your code in the question so it runs in a snippet. You can now see the CORS error in the console – Rory McCrossan May 29 '20 at 11:28
  • is there any other domain by which i can do this ? or it is not possible in anyway ? – cakePHP May 29 '20 at 11:33
  • There are third party services which you can use, however they will be rate-limited. As per the first comment, the work around is to make the cross-domain request from your server side code instead – Rory McCrossan May 29 '20 at 11:36

0 Answers0