Skip to content

nieh0325ubuntu/web-content-analyzer

Repository files navigation

Web Content Analyzer

AI 驅動的網頁內容分析與翻譯工具,使用 Playwright 進行動態網頁爬蟲。

TypeScript Playwright License

功能特性

  • 動態網頁爬蟲 - 使用 Playwright 瀏覽器自動化,支援 JavaScript 渲染的網站
  • 內容提取與清理 - 整合 @mozilla/readability 提取主要內容
  • 身份驗證系統 - 完整的 OAuth2、JWT Token、用戶管理服務
  • HTML 轉 Markdown - 使用 Turndown 將網頁內容轉換為 Markdown 格式
  • Express API 服務 - 提供 RESTful API 接口
  • 速率限制與安全 - 內建 express-rate-limit 和 helmet 安全防護

技術棧

  • 核心: TypeScript、Node.js 18+
  • 爬蟲: Playwright、Cheerio、JSDOM
  • Web 服務: Express.js、Helmet、Rate Limit
  • 身份驗證: JWT、OAuth2
  • 測試: Jest、ts-jest
  • 工具: ESLint、Prettier

快速開始

環境需求

  • Node.js >= 18.0.0
  • npm >= 9.0.0
  • Playwright 瀏覽器

安裝

# 克隆專案
git clone https://github.com/nieh0325ubuntu/web-content-analyzer.git
cd web-content-analyzer

# 安裝依賴
npm install

# 安裝 Playwright 瀏覽器
npx playwright install

開發

# 開發模式(熱重載)
npm run dev

# 編譯專案
npm run build

# 執行測試
npm test

# 測試覆蓋率報告
npm run test:coverage

程式碼檢查

# 檢查程式碼風格
npm run lint

# 自動修復風格問題
npm run lint:fix

# 格式化程式碼
npm run format

# 型別檢查
npm run type-check

專案結構

src/
├── auth/               # 身份驗證模組
│   ├── auth.service.ts
│   ├── oauth2.service.ts
│   ├── token.service.ts
│   ├── user.service.ts
│   ├── routes.ts
│   ├── types.ts
│   └── config.ts
├── core/               # 核心爬蟲邏輯
│   └── base-scraper.ts
├── utils/              # 工具函式
├── types/              # TypeScript 型別定義
├── config/             # 設定檔
├── tests/              # 測試檔案
│   ├── auth.test.ts
│   ├── base-scraper.test.ts
│   └── utils.test.ts
└── index.ts            # 主要進入點

API 端點

身份驗證

  • POST /auth/login - 用戶登入
  • POST /auth/register - 用戶註冊
  • POST /auth/refresh - 刷新 Token
  • POST /auth/logout - 用戶登出

OAuth2

  • GET /auth/oauth/authorize - OAuth2 授權
  • POST /auth/oauth/token - 獲取 Access Token
  • GET /auth/oauth/userinfo - 獲取用戶資訊

爬蟲服務

  • POST /scrape - 爬取網頁內容
  • GET /scrape/status/:id - 查詢爬取狀態

配置

建立 .env 檔案:

# 伺服器設定
PORT=3000
NODE_ENV=development

# JWT 設定
JWT_SECRET=your-secret-key
JWT_EXPIRES_IN=1h

# OAuth2 設定
OAUTH_CLIENT_ID=your-client-id
OAUTH_CLIENT_SECRET=your-client-secret
OAUTH_REDIRECT_URI=http://localhost:3000/auth/callback

# 速率限制
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100

測試

# 執行所有測試
npm test

# 監看模式
npm run test:watch

# 執行特定測試檔案
npx jest src/tests/base-scraper.test.ts

# 執行符合名稱的測試
npx jest --testNamePattern="initialization"

貢獻

  1. Fork 本專案
  2. 建立功能分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 開啟 Pull Request

授權

本專案使用 MIT 授權條款。

致謝


Ultraworked with Sisyphus

About

A TypeScript web content analyzer with scraping, authentication, and structured page analysis.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors