venfiw Posted yesterday at 04:36 PM Report Posted yesterday at 04:36 PM manager.setCookies(cookies, (err) => { // console.log(manager) console.log("### 准备连接报价API") if(err){ console.log("## 连接报价API失败") console.log("## ERRmessage:" + err); } else { console.log("## 连接报价API成功"); manager.getInventoryContents(730, 2, true, function (err, inventory){ console.log("tradeable",inventory.length); tradeablecount = inventory.length; }); manager.getInventoryContents(730, 16, false, function (err, inventory){ console.log("protect",inventory.length); protectcount = inventory.length; }); if (inventorycount!="") { getMarketListings(cookies); } } }); function getMarketListings(cookies) { console.log("### 开始查询Steam市场上架数量"); // 构建cookie字符串 let cookieString = ''; if (Array.isArray(cookies)) { cookieString = cookies.join('; '); } else { cookieString = cookies; } // 第一步:先访问资格检查页面 let eligibilityOptions = { url: 'https://steamcommunity.com/market/eligibilitycheck/?goto=%2Fmarket%2F', headers: { 'Cookie': cookieString, 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'Accept-Language': 'zh-CN,zh;q=0.9,is;q=0.8', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache', 'DNT': '1', 'Upgrade-Insecure-Requests': '1', 'Sec-Fetch-Site': 'none', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-User': '?1', 'Sec-Fetch-Dest': 'document', 'sec-ch-ua': '"Not;A=Brand";v="99", "Google Chrome";v="139", "Chromium";v="139"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"' }, followRedirect: false, // 不自动跟随重定向 timeout: 30000, gzip: true }; // 如果使用代理,添加代理配置 if (apiproxy === "1") { if (proxyset && proxyset.indexOf("http") >= 0) { eligibilityOptions.proxy = proxyset; } else if (proxyset && proxyset.indexOf("sock") >= 0) { eligibilityOptions.socksProxy = proxyset; } else if (proxyipuse) { eligibilityOptions.proxy = "http://" + proxyipuse; } } request(eligibilityOptions, function(error, response, body) { if (error) { console.log("## 资格检查失败: " + error); return; } // 获取新的cookies let newCookies = cookieString; if (response.headers['set-cookie']) { const additionalCookies = response.headers['set-cookie'].map(cookie => { return cookie.split(';')[0]; }).join('; '); newCookies += '; ' + additionalCookies; } console.log("## 资格检查完成,准备访问市场页面"); // 第二步:访问市场页面 let marketOptions = { url: 'https://steamcommunity.com/market/', headers: { 'Cookie': newCookies, 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'Accept-Language': 'zh-CN,zh;q=0.9,is;q=0.8', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache', 'DNT': '1', 'Upgrade-Insecure-Requests': '1', 'Sec-Fetch-Site': 'none', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-User': '?1', 'Sec-Fetch-Dest': 'document', 'sec-ch-ua': '"Not;A=Brand";v="99", "Google Chrome";v="139", "Chromium";v="139"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"' }, followRedirect: true, maxRedirects: 3, timeout: 30000, gzip: true }; // 添加代理配置 if (apiproxy === "1") { if (proxyset && proxyset.indexOf("http") >= 0) { marketOptions.proxy = proxyset; } else if (proxyset && proxyset.indexOf("sock") >= 0) { marketOptions.socksProxy = proxyset; } else if (proxyipuse) { marketOptions.proxy = "http://" + proxyipuse; } } if (inventorycount!="") { request(marketOptions, function(marketError, marketResponse, marketBody) { if (marketError) { console.log("## 查询市场上架数量失败"); console.log("## ERRmessage:" + marketError); return; } if (marketResponse.statusCode !== 200) { console.log("## 查询市场上架数量失败,状态码:" + marketResponse.statusCode); return; } try { // 使用cheerio解析HTML const $ = cheerio.load(marketBody); const marketListingsElement = $('#my_market_selllistings_number'); if (marketListingsElement.length > 0) { const listingscount = marketListingsElement.text().trim(); console.log("market: " + listingscount); marketcount = listingscount; const inventorycounttotal = "["+tradeablecount+","+protectcount+","+marketcount+"]"; if (inventorycount!=0) { request(Config.inventorycount.replace("{steamid64}",client.steamID).replace("{inventorycount}",inventorycounttotal), (err, res, body) => { if (err) {console.log("@debug inventorycount")}else{console.log("\n### 成功上传API inventorycount")} }) } } else { console.log("## 未找到市场上架数量元素 (my_market_selllistings_number)"); } } catch (parseError) { console.log("## 解析市场页面失败"); console.log("## ERRmessage:" + parseError); } }); } }); } i use this code can get protect tradeable marketlisting itemcount but now steam update a patch, item which marketlisting still use one shot on inventory, and it will belong protectcount, is there any way to get is clear? Quote
venfiw Posted yesterday at 05:50 PM Author Report Posted yesterday at 05:50 PM (edited) manager.getInventoryContents(730, 2, true, function (err, inventory){ console.log("tradeable",inventory.length); tradeablecount = inventory.length; }); manager.getInventoryContents(730, 16, false, function (err, inventory){ console.log("protect",inventory.length); protectcount = inventory.length; if (inventorycount!="") { getMarketListings(cookies); } }); ****** if (marketListingsElement.length > 0) { const listingscount = marketListingsElement.text().trim(); console.log("market: " + listingscount); const parsedMarketCount = parseInt(String(listingscount).replace(/,/g, ''), 10); marketcount = Number.isNaN(parsedMarketCount) ? 0 : parsedMarketCount; const adjustedProtectCount = Math.max(0, protectcount - marketcount); const inventorycounttotal = "["+tradeablecount+","+adjustedProtectCount+","+marketcount+"]"; if (inventorycount!=0) { request(Config.inventorycount.replace("{steamid64}",client.steamID).replace("{inventorycount}",inventorycounttotal), (err, res, body) => { if (err) {console.log("@debug inventorycount")}else{console.log("\n### 成功上传API inventorycount")} }) } } else { console.log("## 未找到市场上架数量元素 (my_market_selllistings_number)"); } now i use this code. but i want to know is there any way to get marketlisting like use manager.getInventoryContents because they on inventory now Edited yesterday at 05:52 PM by venfiw Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.