Yesterday I was trying to download chess PGN from chess.com. The process is pretty easy but then one thing led to another and I thought to Write a PGN Parser in java so that I could fetch all Infos from the PGN file.

What is PGN in Chess

PGN stands for Portable Game Notation. In short, PGN consists of all moves played in the game along with other information about the game eg: players, result, round number, result etc

Format of PGN

The General format of PGN is as below

[Event “?”]
[Site “?”]
[Date “????.??.??”]
[Round “?”]

1. e4 e5 2. Nf3 Nc6 3. Bc4 Nf6 ….

Parsing PGN in Java

PGN keeps all information on a separate line. So if we split the PGN text with a new line then we’ll end up having an array of strings and each element will contain only one piece of information. The last element will contain all the moves.

Once we get the array, We will scan each element and will match that with standard information template, that will give us corresponding PGN value.

Here’s code

You can download the Source code for LiChess.com and Chess.com scrapper from

Chess-archiver allows you to download all games of a given user from chess.com and Lichess.com

Leave a comment

Your email address will not be published. Required fields are marked *