我正在尝试获取蒸汽市场上物品的价格历史记录。我找到了一个返回特定商品价格历史记录的链接(几乎每个有关从该网站的市场获取价格历史记录的问题都提到了这一点)。
当我登录 Steam 时,它在浏览器中工作正常,但是当我尝试在 python 中执行相同的操作时,它返回一个空列表(当我尝试在浏览器中执行此操作而不登录时,也会发生同样的情况- 在 Steam 中)。这是我的 python 代码(使用请求库):
import requests
params = {'country': 'RU', 'currency': 5, 'appid': 730, 'market_hash_name': 'Falchion%20Case'}
data = requests.get('http://steamcommunity.com/market/pricehistory', params=params)
print(data.text)
所以,问题是:有没有办法在使用 python(或其他语言)发出请求时模拟在 Steam 中登录?
您需要将
Cookie
键 steamLogin
设置为您的会话 ID。您可以在浏览器上登录并获取该值。
cookie = {'steamLogin': '76561198058933558%7C%7C2553658936E891AAD'}
data = requests.get('http://steamcommunity.com/market/pricehistory/?country=PT¤cy=3&appid=730&market_hash_name=Falchion%20Case', cookies=cookie);
我在这里使用了随机的
steamLogin
值,将其更改为您的会话 ID。
您也可以尝试通过 python 执行登录,但您可能想关闭 Steam Guard 以使事情变得更简单。我本来会演示自动执行登录,但我不希望禁用我的 Steam 防护并获得 15 天的交易限制。
写着
{'steamLogin':'...'}
的地方,应该是{'steamLoginSecure':'...'}
。所以正确的代码是:
cookie = {'steamLoginSecure': '76561198058933558%7C%7C2553658936E891AAD'}
data = requests.get('http://steamcommunity.com/market/pricehistory/?country=PT¤cy=3&appid=730&market_hash_name=Falchion%20Case', cookies=cookie)
我已经使用了 Laravel Freamwork 那么如何获得 steamLoginSecure https://steamcommunity.com/market/pricehistory?country=RU¤cy=5&appid=730&market_hash_name=Falchion%20Case