1

Every chess.com game has a game ID. For example https://www.chess.com/game/live/2485075845 2485075845 is the game ID. When you go to this URL it is possible to download the PGN by clicking the share button.
Is there a way to do this programmatically (say using Python) so I can pass in the game ID and download it directly using a Python script
I noticed that https://www.chess.com/callback/live/game/2485075845 gives all the data that is related to the game but the moveList is showing in some kind of hashed format which I have no idea how to decode.

Appreciate if anyone can help with this.

EDIT
managed to achieve what I wanted by using Hauptideal's answer. For anyone interested here is the code for downloading games of a tournament. Might have edge cases though. Also some rare cases the API fails to fetch a user's games which is a downside.

1
  • I'd suggest that chess.com probably are protecting or obfuscating the format so that it will be very expensive to use user-centered methods to download PGN games. They may also have additional layers of protection. See the article on Web Scraping on Wikipedia, especially the material on Legal Issues. You are probably better off asking chess.com for a B2B interface: but if they provide it, it is likely to be at a price.
    – user30536
    Commented Nov 22, 2023 at 18:30

1 Answer 1

3

It is possible to download games from chess.com, otherwise services like Opening Tree would not work.

Chess.com has published it's data API.

It includes endpoints for downloading games in PGN format.

You can access this API programmatically, including Python. It is possible that you have to download multiple games from a player in a batch and then filter the game you're interested in (e.g, using the game URL/game ID, see data format below).

The data format for games that are returned by this API is

    {
  "white": { // details of the white-piece player:
    "username": "string", // the username
    "rating": 1492, // the player's rating after the game finished
    "result": "string", // see "Game results codes" section
    "@id": "string" // URL of this player's profile
  },
  "black": { // details of the black-piece player:
    "username": "string", // the username
    "rating": 1942, // the player's rating after the game finished
    "result": "string", // see "Game results codes" section
    "@id": "string" // URL of this player's profile
  },
  "accuracies": { // player's accuracies, if they were previously calculated
    "white": float,
    "black": float
  },
  "url": "string", // URL of this game
  "fen": "string", // final FEN
  "pgn": "string", // final PGN
  "start_time": 1254438881, // timestamp of the game start (Daily Chess only)
  "end_time": 1254670734, // timestamp of the game end
  "time_control": "string", // PGN-compliant time control
  "rules": "string", // game variant information (e.g., "chess960")
  "eco": "string", //URL pointing to ECO opening (if available),
  "tournament": "string", //URL pointing to tournament (if available),  
  "match": "string", //URL pointing to team match (if available)  
}
4
  • does most of these apis require a userId as well. Since i'm only interested in a single game it would take a lot of time to say filter it out from a user having 1000s of games
    – cmgchess
    Commented Nov 23, 2023 at 3:59
  • Why do you think would it take a lot of time to filter the games? Even processing 1000 games should not take more than a fraction of a second. The server response will not be slower for 1000 games than for 1 game, except the actual download time (that's of course longer for more data). Plus, you can get monthly archives, so it will never be 1000s of games, unless the player really played 1000s of games in a single month.
    – Hauptideal
    Commented Nov 23, 2023 at 13:55
  • actually my plan is to collect all the game ids of a certain titled tuesday and create a pgn of all the games. will see how it goes
    – cmgchess
    Commented Nov 23, 2023 at 15:56
  • 1
    Thanks it worked and i managed to achieve what i wanted. Link for anyone interested
    – cmgchess
    Commented Dec 3, 2023 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.