因此,我编写了这个小程序来更新 Steam 市场上特定商品的最低价格,它运行一个循环并获取 json 响应。
最初它工作正常,显示价格,但一段时间后它显示错误。
程序代码:
import json
import requests
def GetPrice () :
response = requests.get ('https://steamcommunity.com/market/priceoverview/?appid=264710¤cy=1&market_hash_name=Planet%204546B%20Postcard')
json_data = {}
json_data = json.loads (response.text)
return json_data ["lowest_price"]
while True :
print (GetPrice ())
Run Code Online (Sandbox Code Playgroud)
这是程序的输出:
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\item_price.py", line 16, in <module>
print (GetPrice ())
File "C:\Users\Admin\Desktop\item_price.py", line 12, in GetPrice
return json_data …Run Code Online (Sandbox Code Playgroud)