Has Yahoo finance web service disappeared? API changed? Down temporarily?

后端 未结 9 1508
礼貌的吻别
礼貌的吻别 2020-11-27 13:12

For quite some time I\'ve been using the following REST API to query Yahoo finance for current prices. It is documented in several Stack Overflow posts, e.g. Yahoo finance

9条回答
  •  孤城傲影
    2020-11-27 13:53

    It is redirecting to the same page, but adding the parameter "bypass=true", which gives an error.

    EDIT: The answer given by https://stackoverflow.com/users/6593038/hemant-prasad is working for me. When changing the user agent to a mobile device, the API works fine, and doesn't redirect so far.

    This is the code I'm using in Java (it's for the XML version, but it can be use for JSON as well):

    URL url = new URL ("https://finance.yahoo.com/webservice/v1/symbols/" + stocks + "/quote");
    HttpURLConnection urlc = (HttpURLConnection) url.openConnection ();
    urlc.setRequestProperty ("User-Agent", "Mozilla/5.0 (Linux; Android 6.0; MotoE2(4G-LTE) Build/MPI24.65-39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.81 Mobile Safari/537.36");
    Document xml = DocumentBuilderFactory.newInstance ().newDocumentBuilder ().parse (urlc.getInputStream ());
    

提交回复
热议问题