March 2026

Pulling Magic Commander Rankings from EDHREC

I'm working on a tool to help me build Magic Decksmdb. It'll let me search and assemble cards from data via Scryfallsf. I also want to see other folks are doing. For example, which are the most used commanders. I'm grabbing data from EDHRECedh for that.

This is the script I'm using to pull in the raw data.

#!/usr/bin/env python3

import json
import urllib.request

url = "https://edhrec.com/commanders"
output_path = "commanders.json"

def get_json():
    response = urllib.request.urlopen(url)
    html = response.read().decode('utf-8')
    parts = html.split('<script id="__NEXT_DATA__" type="application/json">')
    content = parts[1].split('</script>')
    data = json.loads(content[0])
    with open(output_path, "w") as _out:
        _out.write(json.dumps(data, sort_keys=True, indent=2, default=str))

if __name__ == "__main__":
    get_json()

The code's a little brittle in terms of doing a split to pull out the data instead of more advanced parsing with something like Beautiful Soupbs. That's not a big deal. If they change the page and things break I'll just update the script.

-a

end of line

Endnotes

The EDHREC data uses Scryfall IDs. Combining data sets is no fuss, no muss.

Footnotes

The little tool I'm making to make Magic decks. Still very much a work in progress at press time.

The place to search for Magic cards. Even better, they provide bulk data downloads.

Fantastic fan content for all things Magic. They've got articles and stuff which I'm sure are great. I'm only there for the deck lists and rankings though.

For those times when doing simple splits doesn't get you what you need, try Beautiful Soup. It's the only way to fly with python HTML parsing.