「ふもとっぱら」の空き状況をplaywrightでスクレイピング

# ブラウザ操作コード自動生成
playwright codegen fumotoppara.secure.force.com -o fumotoppara.py
import pandas as pd
from playwright.sync_api import Playwright, sync_playwright


def run(playwright: Playwright) -> pd.DataFrame:

    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()

    dfs = []

    # Open new page
    page = context.new_page()

    # Go to https://fumotoppara.secure.force.com/

    page.goto("https://fumotoppara.secure.force.com/")

    months = [
        i.get_attribute("value")
        for i in page.query_selector_all("select#f_nengetsu > option")
    ]

    for i, month in enumerate(months):

        if i > 0:

            page.select_option('select[name="f_nengetsu"]', month)
            # 読み込むまで待機
            page.wait_for_load_state("networkidle")

        df_tmp = pd.read_html(page.content())[0]
        df_tmp["月"] = month

        dfs.append(df_tmp[:-1])

    # Close page
    page.close()

    # ---------------------
    context.close()
    browser.close()

    return pd.concat(dfs).reset_index(drop=True)


with sync_playwright() as playwright:

    df0 = run(playwright)

df_date = (
    (df0["月"] + df0["日付"])
    .str.extract("(\d{4})年(\d{1,2})月(\d{1,2})日")
    .rename(columns={0: "year", 1: "month", 2: "day"})
    .astype(int)
)

df0["日付"] = pd.to_datetime(df_date)

df0.drop("月", axis=1, inplace=True)

df0.set_index(["日付", "曜日"], inplace=True)

df0

# 日付別予約可能

df1 = df0[
    df0.isin(["○", "△"]).any(axis=1)
].copy()

df1

df1.to_csv("fumotoppara.csv", encoding="utf_8_sig")