這個專案提供一個簡單的 Playwright 指令稿,先「渲染」網頁再儲存結果,適合用來抓取需要前端運算才會出現內容的網站。預設目標是 104 人力銀行的公司頁面 https://www.104.com.tw/company/1xzkino,也可以透過命令列參數指定其他網址。
- Python 3.10+
- 安裝依賴:
若執行時仍遇到
pip install -r requirements.txt playwright install chromium
Executable doesn't exist at ...chromium_headless_shell...的錯誤, 指令稿會嘗試自動下載瀏覽器,但也可以手動執行playwright install --with-deps chromium再重試。
將頁面渲染後的 HTML 儲存到 output/company.html:
python scrape_render.py指定網址與輸出路徑,並同時截圖:
python scrape_render.py "https://www.104.com.tw/company/1xzkino" --output output/company.html --screenshot output/company.png產出的 HTML 可用瀏覽器開啟檢查內容,若需要後續再以 BeautifulSoup 等工具解析,也能直接讀取產出的檔案。
在 Render 上啟動 Worker 時,可將 Start Command 設為:
python scrape_render.py建議在 Build Command 中加入 Playwright 瀏覽器安裝,以確保執行時可使用 Chromium:
pip install -r requirements.txt && playwright install --with-deps chromium