Skip to content

Instantly share code, notes, and snippets.

@acrosby
Created December 7, 2023 18:19
Show Gist options
  • Save acrosby/08418dde7b2e0e593f7c013c41d1ed56 to your computer and use it in GitHub Desktop.
Save acrosby/08418dde7b2e0e593f7c013c41d1ed56 to your computer and use it in GitHub Desktop.
Scrape CT Images from Scan of the Month Website
import base64
import requests
import os
from io import StringIO
output_path = "output"
default_url = "https://www.scanofthemonth.com/scans/game-boy-compendium"
source = requests.get(default_url)
ujson = set([x.strip().replace('"', "").split("=")[-1] for x in source.text.split("\n") if "data-src=" in x])
for jurl in ujson:
data = requests.get(jurl)
data = data.json()
folder = data["nm"]
if not os.path.exists(os.path.join(output_path, folder)):
os.mkdir(os.path.join(output_path, folder))
for layer, asset in zip(data["layers"], data["assets"]):
imgname = layer["nm"]
encodedimg = asset["p"].replace("data:image/png;base64,", "")
with open(os.path.join(output_path, folder, imgname), "wb") as img:
base64.decode(StringIO(encodedimg), img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment