寻找一种方法来获取所有Steam头图像

时间:2014-10-22 10:50:15

标签: image screen-scraping steam

基本上我一直试图找到一种很好的简单方法来自动获取大量的蒸汽标题图像以用作Windows平铺图标

所有标题都存储在此处

http://cdn.akamai.steamstatic.com/steam/apps/10/header.jpg

号码是游戏的ID

我已经看过一些关于抓取的内容,但我不确定如何做一些基本上下载所有图像的内容

/apps/10/header.jpg

/apps/500000/header.jpg

等等

1 个答案:

答案 0 :(得分:2)

我在Python中构建了一个小脚本(版本2,但它在使用3时运行良好)。这会使用requests库,所以如果你没有安装,你也需要它。

设置:

  • 将此脚本复制到文件中并使用python扩展名保存。示例:download_headers.py
  • 在保存download_headers.py的同一目录中,创建名为game_headers
  • 的目录

脚本:

import requests
import os

save_location = "game_headers"

base_url = "http://store.steampowered.com/api/appdetails/?appids=%s&filters=basic"

header_images = []
full_path = os.path.abspath(save_location)

for x in [440,65980,281690,1]:
    r = requests.get(base_url % (x)).json()
    try:
        header_images.append((x, r[unicode(x)]['data']['header_image']))
    except KeyError:
        print "AppID {} => Did not return data".format(x)

# Download the images

for i in header_images:
    print "Downloading header image for AppID {}".format(i[0])
    r = requests.get(i[1], stream=True)
    if r.status_code == 200:
        with open(os.path.join(full_path, "{}_header.jpg".format(unicode(i[0]))), 'wb') as f:
            for chunk in r.iter_content():
                f.write(chunk)

输出:

> python headers.py
AppID 1 => Did not return data
Downloading header image for AppID 440
Downloading header image for AppID 65980
Downloading header image for AppID 281690

现在game_headers目录中有三张图片。

修饰

正如目前所写,该脚本仅查找应用ID 440659802816901的图片。如果要使其成为全范围的ID,请修改以下行:

for x in [440,65980,281690,1]:

是一系列整数:

for x in range(420,450):

这将导致许多应用ID不存在,但如上所述,应用ID 1会跳过这些ID:

AppID 421 => Did not return data
AppID 422 => Did not return data
AppID 423 => Did not return data
AppID 424 => Did not return data
AppID 425 => Did not return data
AppID 426 => Did not return data
AppID 427 => Did not return data
AppID 428 => Did not return data
AppID 429 => Did not return data
AppID 430 => Did not return data
AppID 431 => Did not return data
AppID 432 => Did not return data
AppID 433 => Did not return data
AppID 434 => Did not return data
AppID 435 => Did not return data
AppID 436 => Did not return data
AppID 437 => Did not return data
AppID 438 => Did not return data
AppID 439 => Did not return data
AppID 441 => Did not return data
AppID 442 => Did not return data
AppID 443 => Did not return data
AppID 444 => Did not return data
AppID 445 => Did not return data
AppID 446 => Did not return data
AppID 447 => Did not return data
AppID 448 => Did not return data
AppID 449 => Did not return data
Downloading header image for AppID 420
Downloading header image for AppID 440

注释

这利用了appdetails非官方的Steam Storefront API。凭借这一点知识,这意味着如果Valve修改它,他们可能不会提前宣布它。它会传递basic过滤器,以减少返回的数据量(header_image是此过滤器的一部分)。

您可以通过将逗号分隔的appids字符串传递给base_url来提高性能。通常,Valve在这些类型的API调用中一次允许100个。我没有通过这个特定的电话测试过。如果这样做,则必须遍历响应以检查每个返回的应用程序。

相关问题