import asyncio from playwright.async_api import async_playwright async def fetch_train_info(): async with async_playwright() as p: browser = await p.chromium.launch() page = await browser.new_page() # ページにアクセスし、JavaScriptの実行を待つ await page.goto("https://traininfo.jreast.co.jp/train_info/kanto.aspx") # 必要に応じて指定時間待機する(例: 5秒待機) await page.wait_for_timeout(5000) # 運行情報のテキストを取得 content = await page.content() # HTML全体を取得 train_info = await page.inner_text("body") # 必要なセレクタを指定して取得 print(train_info) await browser.close() # 実行 asyncio.run(fetch_train_info()) exit()