Created
October 1, 2023 07:24
-
-
Save aimerneige/7515d5787fedaa53e51640650001e376 to your computer and use it in GitHub Desktop.
Parse lichess link and get pgn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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