2015-07-31 02:39:40 +08:00
|
|
|
var SteamCommunity = require('../index.js');
|
|
|
|
var Cheerio = require('cheerio');
|
|
|
|
|
|
|
|
SteamCommunity.prototype.getMarketApps = function(callback) {
|
|
|
|
var self = this;
|
2016-03-05 07:26:47 +08:00
|
|
|
this.httpRequest('https://steamcommunity.com/market/', function (err, response, body) {
|
2016-03-05 12:59:49 +08:00
|
|
|
if (err) {
|
|
|
|
callback(err);
|
2015-07-31 02:39:40 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-03-05 12:59:49 +08:00
|
|
|
|
2015-07-31 02:39:40 +08:00
|
|
|
var $ = Cheerio.load(body);
|
|
|
|
if ($('.market_search_game_button_group')) {
|
|
|
|
apps = {};
|
|
|
|
$('.market_search_game_button_group > a').each(function (i, element) {
|
|
|
|
var e = Cheerio.load(element);
|
|
|
|
var name = e('.game_button_game_name').text().trim();
|
|
|
|
var url = element.attribs.href;
|
|
|
|
var appid = url.substr(url.indexOf('=') + 1);
|
|
|
|
apps[appid] = name;
|
|
|
|
});
|
2015-07-31 04:45:07 +08:00
|
|
|
callback(null, apps);
|
2015-07-31 02:39:40 +08:00
|
|
|
} else {
|
2015-07-31 04:28:28 +08:00
|
|
|
callback(new Error("Malformed response"));
|
2015-07-31 02:39:40 +08:00
|
|
|
}
|
2016-03-05 08:35:04 +08:00
|
|
|
}, "steamcommunity");
|
|
|
|
};
|