【问题标题】:Get information in JSON format from steam page, using jquery使用 jquery 从 Steam 页面获取 JSON 格式的信息
【发布时间】:2015-11-01 12:32:32
【问题描述】:

我已经找到了很多关于此的信息,但它仍然不起作用:/

所以我有这个 JSON 格式的 steam page,我想获得不带 PHP 的最低价格变量,因为我将它用于我的 chrome 扩展。请帮帮我。

【问题讨论】:

  • 除非该 URL 启用了 CORS,或者返回 JSONP 格式的数据,否则由于Same Origin Policy,您无法通过 Javascript 访问它。您需要使用 PHP 或任何其他服务器端语言来为您发出请求。
  • 但是 PHP 不适用于 chrome 扩展 :c
  • 那恐怕你倒霉了。
  • 据我所知,steam 可以做到这一点。我已经在 StackOverflow 上回答了类似的问题。寻找它。
  • 对不起,我可能弄错了主题,请看这里:stackoverflow.com/a/26983323/1995006

标签: jquery ajax json


【解决方案1】:
fetch("https://steamcommunity.com/market/priceoverview/?currency=5&appid=570&market_hash_name=Huntling").then(function(response){
  return response.json();
}).then(function(response){
  console.log(response.lowest_price);
});

或者因为您使用的是 jQuery:

$.get("https://steamcommunity.com/market/priceoverview/?currency=5&appid=570&market_hash_name=Huntling", function(response){
  console.log(response.lowest_price);
});

如果您要进行扩展,则需要在清单中为 CORS 配置它:https://developer.chrome.com/extensions/xhr#requesting-permission 类似这样的东西:

{
  "name": "My extension",
  ...
  "permissions": [
    "https://steamcommunity.com/*"
  ],
  ...
}

【讨论】:

    猜你喜欢
    • 2012-07-14
    • 2020-07-26
    • 1970-01-01
    • 2012-07-05
    • 2021-11-29
    • 2019-12-18
    • 2019-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多