Skip to content

Instantly share code, notes, and snippets.

@aimerneige
Created October 1, 2023 07:24
Show Gist options
  • Save aimerneige/7515d5787fedaa53e51640650001e376 to your computer and use it in GitHub Desktop.
Save aimerneige/7515d5787fedaa53e51640650001e376 to your computer and use it in GitHub Desktop.
Parse lichess link and get pgn
import re
import io
import chess.pgn
import requests
url = "https://lichess.org/onwfe9NcyG6W"
response = requests.get(url)
html = response.text
pgn_string = re.findall(r'<div class="pgn">(.*?)</div>', html, re.S)[0]
# print(game_pgn)
pgn = io.StringIO(pgn_string)
game = chess.pgn.read_game(pgn)
board = game.board()
for move in game.mainline_moves():
print(board)
board.push(move)
_=input("Press any key to continute...")
print(board)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment