[英]Get Steam Community Market price history with node.js
我在從 Steam 獲取物品的價格歷史記錄時遇到問題。 通過查看其他問題,我設法學會了一種構建鏈接的絕妙方法,該鏈接確實為我提供了物品的價格歷史記錄,我的問題是您必須登錄 Steam 才能獲取此數據。 我如何查看這些數據,就好像我通過 http 請求登錄一樣? 我已經閱讀了其他線程,他們談到了瀏覽器會話以及在我的情況下應該如何設置會話 ID 的 cookies 但我還沒有設法讓它在節點中工作。 我得到的狀態碼是 400。
這是我的代碼:
const https = require('https');
const options = {
host: 'steamcommunity.com',
path: '/market/pricehistory/?country=SE¤cy=3&appid=730&market_hash_name=CS20%20Case',
method: 'GET',
headers: {
'Cookie': `steamLoginSecure=THE SESSION ID I GOT FROM WRITING
"document.cookie" IN THE DEV CONSOLE`
}
}
const req = https.request(options, res => {
console.log(res.statusCode);
console.log(res.headers);
let body = '';
res.on('data', data => {
body += data;
});
res.on('end', () => console.log(body));
}).on('error', error => console.log(error));
req.end();
我不確定我的代碼是否有任何問題,或者如何 go 來解決我遇到的這個問題。 我非常感謝我能得到的任何幫助。
似乎 Steam 已經刪除了“steamLogin”cookie,從而解釋了為什么去年有這么多人在他們的代碼中使用它時遇到了問題。 相反,您想使用“steamLoginSecure”cookie。
首先,您需要登錄到https://steamcommunity.com 。 其次,您要找到“steamLoginSecure”cookie 並復制其中包含的內容。 對於鉻,這將是:
設置 > 高級 > 隱私和安全 > 站點設置 > Cookies 和站點數據 > 查看所有 cookies 和站點數據 > steamcommunity.com > steamLoginSecure
現在復制“steamLoginSecure”的內容並將其作為 cookie 放在您的標題中。
這是我最終得到的最終代碼:
const https = require('https');
const options = {
host: 'steamcommunity.com',
path: '/market/pricehistory/?country=SE¤cy=3&appid=730&market_hash_name=CS20%20Case',
method: 'GET',
headers: {
'Cookie': 'steamLoginSecure=THE CONTENT OF "steamLoginSecure" HERE'
}
}
const req = https.request(options, res => {
console.log(res.statusCode);
console.log(res.headers);
let body = '';
res.on('data', data => {
body += data;
});
res.on('end', () => console.log(body));
}).on('error', error => console.log(error));
req.end();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.