我有一个Node.js脚本,该脚本搜索增加的URL以查看用户是否在库存中有某个项目。如果是,则显示其用户ID。
这是脚本:
// Import the scraping libraries
var request = require("request");
var cheerio = require("cheerio");
// Array for the user IDs which match the query
var matches = [];
// Do this for all possible users
function makeRequest(i){
var location = "http://www.roblox.com/Trade/inventoryhandler.ashx?filter=0&userid=" + i + "&page=1&itemsPerPage=14";
request(location, function (error, response, body) {
console.log('request made for id '+ i);
if (!error) {
// Load the website content
var $ = cheerio.load(body);
var bodyText = $("body").text();
// Search the website content for gaming
if (bodyText.indexOf("gaming") > -1) {
console.log("Found gaming in inventory of user ", i);
// Save the user ID, if gaming was found
matches.push(i);
}
// Something goes wrong
} else {
console.log(error.message);
}
if(i==261){
console.log("All users with gaming in inventory: ", matches);
return;
}
makeRequest(i+1);
});
}
makeRequest(1);
链接http://www.roblox.com/Trade/inventoryhandler.ashx?filter=0&userid=261&page=1&itemsPerPage=14上有“游戏”文字,但在执行后会返回没有结果。
您能否帮助我确定脚本的问题,以便显示那些在其广告资源中进行游戏的人的用户ID?