from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import pandas as pd
import time
#--| Setup
options = Options()
#options.add_argument("--headless")
browser = webdriver.Chrome(executable_path=r'chromedriver.exe', options=options)
#--| Parse or automation
browser.get('https://chess24.com/en/watch/live-tournaments/world-rapid-championship-2019/4/1/5')
soup = BeautifulSoup(browser.page_source, 'lxml')
#browser.implicitly_wait(5)
time.sleep(4)
title = soup.select('h2.title')
print(title[0].text)
# Get table
df = pd.read_html(browser.page_source, header=None)
standings = df[2]
standings.columns = ["Rank", "Name", "Score", "Rating"]
standings.head(10)
FIDE World Rapid Championship
Rank | Name | Score | Rating | |
---|---|---|---|---|
0 | 1 | Wang, Hao | 4½/5 | 2748.0 |
1 | 2 | Mamedyarov, Shakhriyar | 4½/5 | 2752.0 |
2 | 3 | Smirin, Ilia | 4½/5 | 2584.0 |
3 | 4 | Duda, Jan-Krzysztof | 4½/5 | 2751.0 |
4 | 5 | Dominguez Perez, Leinier | 4½/5 | 2755.0 |
5 | 6 | Carlsen, Magnus | 4/5 | 2886.0 |
6 | 7 | Guseinov, Gadir | 4/5 | 2691.0 |
7 | 8 | Le, Quang Liem | 4/5 | 2740.0 |
8 | 9 | Zubov, Alexander | 4/5 | 2688.0 |
9 | 10 | Dubov, Daniil | 4/5 | 2752.0 |
# We have a okay player in my country
standings.loc[[5]]
Rank | Name | Score | Rating | |
---|---|---|---|---|
5 | 6 | Carlsen, Magnus | 4/5 | 2886.0 |