botrun-crawler-2
v1.0.0
Published
智慧網頁爬蟲 - 支援動態下載連結偵測、MIME type 分析、政府網站相容
Maintainers
Readme
botrun-crawler
智慧網頁爬蟲 - 支援動態下載連結偵測、MIME type 分析、政府網站相容
安裝
npm install -g botrun-crawlerCLI 使用方法
基本爬取
# 單頁完整爬取
botrun-crawler crawl "https://example.com"
# JSON 格式輸出
botrun-crawler crawl "https://example.com" --json
# 安靜模式
botrun-crawler crawl "https://example.com" -q儲存結果
# 儲存 HTML
botrun-crawler crawl "https://example.com" --save-html page.html
# 儲存純文字(LLM 友善格式)
botrun-crawler crawl "https://example.com" --save-text page.txt
# 儲存下載連結清單
botrun-crawler crawl "https://example.com" --save-downloads urls.txt
# 全部儲存
botrun-crawler crawl "https://example.com" \
--save-html page.html \
--save-text page.txt \
--save-downloads urls.txt效能選項
# 跳過 MIME type 分析(加快速度)
botrun-crawler crawl "https://example.com" --skip-mime命令總覽
| 命令 | 說明 |
|------|------|
| crawl <url> | 單頁完整爬取(推薦) |
| scrape <url> | 簡易版抓取 |
| scrape-batch <file> | 批次抓取多個網址 |
| process <file> | 處理本地檔案 |
| help | 顯示說明 |
crawl 選項
| 選項 | 說明 |
|------|------|
| --json | JSON 格式輸出 |
| --save-html <file> | 儲存原始 HTML |
| --save-text <file> | 儲存純文字 |
| --save-downloads <file> | 儲存下載連結清單 |
| --skip-mime | 跳過 MIME type 分析 |
| -v, --verbose | 詳細模式 |
| -q, --quiet | 安靜模式 |
輸出範例
========================================
單頁完整爬取結果
========================================
網址: https://www.ida.gov.tw/...
標題: 經濟部產業發展署
連結統計
├─ 下載連結: 475 個
│ ├─ PDF: 120
│ ├─ Word: 85
│ └─ 動態連結: 270
├─ 連外連結: 22 個
└─ 內部連結: 675 個Proxy 設定
export HTTPS_PROXY="http://proxy:8080"
export HTTP_PROXY="http://proxy:8080"
export NO_PROXY="localhost,.internal.com"程式庫使用
import { crawlPage } from 'botrun-crawler/crawler';
const result = await crawlPage('https://example.com');
console.log(result.links.downloads.count);子模組
import { PageCrawler, crawlPage } from 'botrun-crawler/crawler';
import { scrapeUrl } from 'botrun-crawler/scraper';
import { fetchWithProxy, fetchMimeType } from 'botrun-crawler/lib';特色
- 動態下載連結偵測:自動識別
download.aspx、getFile.do等動態連結 - MIME Type 分析:自動分類 PDF/Word/Excel 等檔案類型
- 檔名亂碼修正:自動修正 UTF-8 編碼問題
- 政府網站相容:針對台灣政府網站最佳化
License
MIT
