一個基於 Playwright 的進階網頁爬蟲工具,支援:
- ✅ 真實瀏覽器渲染 — 能正確抓取 JavaScript 動態生成的連結與內容
- 🌐 同網域深度控制 — 僅深入同網域頁面,但會記錄所有連結
- 📊 進度條顯示 — 使用
tqdm展示處理進度 - 📝 內容擷取合併 — 輸出所有頁面的純文字內容,方便做文字分析
- 🔗 Canonical 去重 — 避免重複頁面內容
- ✂️ NotebookLM 分檔 — 依字數切割大檔,符合 NotebookLM 單檔上限(20 萬字)
git clone https://github.com/你的帳號/crawl-links-playwright.git
cd crawl-links-playwright
pip install -r requirements.txt
python -m playwright install chromiumplaywright
tqdm
requests
beautifulsoup4python crawl_links_playwright.py \
--start_url https://example.com \
--max_depth 2 \
--output links.csv --headlesspython crawl_links_playwright.py \
--start_url https://example.com \
--max_depth 2 \
--output links.csv \
--dump_text combined_content.txt \
--headlesspython crawl_links_playwright.py \
--start_url https://example.com \
--max_depth 2 \
--output links.csv \
--dump_text combined_content.txt \
--split_for_notebooklm \
--split_word_limit 150000 \
--headless輸出:
combined_content_part1.txt
combined_content_part2.txt
...
| 參數 | 說明 |
|---|---|
--start_url |
起始網址 (必填) |
--max_depth |
最大深度 (必填) |
--output |
輸出 CSV 檔案名稱 (預設: links.csv) |
--delay |
每個頁面請求間隔秒數 (預設: 0.5) |
--wait_until |
等待事件 (load/domcontentloaded/networkidle/commit,預設 networkidle) |
--headless |
啟用無頭模式 |
--user_agent |
自訂 User-Agent |
--accept_language |
語系設定 (預設: en-US,en;q=0.9) |
--dump_text |
合併文字輸出的檔案路徑 |
--text_delay |
每次文字擷取的延遲 (預設: 1.0 秒) |
--dump_same_domain_only |
只輸出同網域文字內容 |
--canonical_dedup / --no_canonical_dedup |
Canonical 去重開關 (預設啟用) |
--split_for_notebooklm |
啟用 NotebookLM 分檔功能 |
--split_word_limit |
每檔最大字數 (預設: 150000) |
| url | depth | source | same_domain |
|---|---|---|---|
| https://example.com | 0 | True |
---
來源: <https://example.com/page1>
Canonical: <https://example.com/page1>
---
[該頁面純文字]
==================================================
- 建立網站全站索引
- 匯總網站文字內容供 NotebookLM / 向量資料庫 使用
- 資料備份或文字探勘 (Text Mining)
Crawl-Links-Playwright/
├── crawl_links_playwright.py # 主程式:Playwright 爬蟲工具
├── README.md # 專案說明文件 (GitHub 首頁)
├── requirements.txt # Python 套件需求清單
├── .gitignore # Git 忽略規則
├── LICENSE # MIT 授權條款
└── (輸出檔案)
├── links.csv # 爬取結果 (連結清單)
├── combined_content.txt # 合併文字內容 (若使用 --dump_text)
├── combined_content_part1.txt # NotebookLM 分檔 (若啟用)
└── combined_content_part2.txt # NotebookLM 分檔 (若啟用)
本專案採用 MIT License。