1

I've gotten the code below working to pull the lastPrice from the JSON data from Yahoo for a certain strike price, but only if I replace url with an actual JSON file. Each time I use the actual URL instead of the file I get a "No 'Access-Control-Allow-Origin' header is present on the requested resource." warning. Is there anything that I'm doing wrong?

$.ajax({
  url: 'https://query1.finance.yahoo.com/v7/finance/options/CL',
  dataType: 'json',
  type: 'get',
  cache: false,
  success: function(data) {
    var jsonStr = JSON.stringify(data);
    document.body.innerHTML = jsonStr;
    $(data.optionChain.result[0].options[0].calls).each(function(index, value) {
      if (value.strike == 85) {
        var test = value.lastPrice;
        console.log(test);
      }
    });
  }
});
sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
  • 1
    Possible duplicate of [Access-Control-Allow-Origin error sending a jQuery Post to Google API's](https://stackoverflow.com/questions/6114436/access-control-allow-origin-error-sending-a-jquery-post-to-google-apis) – Alexander Nied Jul 27 '17 at 02:00
  • 1
    That means that Yahoo Finance does not allow you to scrape their website's content. – Obsidian Age Jul 27 '17 at 02:00
  • You could try scraping via YQL - [HERE](https://developer.yahoo.com/yql/guide/yql-code-examples.html) – sideroxylon Jul 27 '17 at 03:30

0 Answers0