本專案利用 Prefect 建立的 Stock Data Pipeline,透過 Selenium 自動爬取台灣公開的集保戶股權分散表跟每日交易日報,並使用 Streamlit 進行資料視覺化,透過自訓練 model 破解 CAPTCHA。
This project leverages Prefect to build a Stock Data Pipeline, using Selenium to automatically scrape publicly available Taiwan Depository & Clearing Corporation (TDCC) shareholder distribution data and daily trading reports. It also employs Streamlit for data visualization, and utilizes a self-trained model to break CAPTCHA.
- Install Docker
- Install uv
MODE=dev:本地測試用 (Local testing mode)MODE=prod:生產環境使用 (Production mode)
git clone https://github.com/Jeff92316046/stock-data-pipeline.git
cd stock-data-pipeline
cp .env.sample .env- 使用 docker compose 啟動專案
docker compose up -d- 使用 uv 啟動專案
- run crawler
uv sync cp src/crawler/main.py src/main.py uv python src/main.py
- run dashboard
uv sync cp src/dashboard/main.py src/main.py uv python src/main.py
- run crawler
- 自動化資料抓取:定期從 TDCC 跟 TWSE 爬取 集保戶股權分散表 與 每日交易日報 資料。
- 資料視覺化:透過 Streamlit 呈現股東級距分布。
- 可視化流程監控:使用 Prefect UI 監控資料抓取與處理流程。
- 基於規則篩選潛力股(Rule-based stock selection)。
- 機器學習模型訓練(Training models for data analysis)。
- 股票價格爬取與整合(Stock price collection and integration)。
- 優化資料搜尋功能(Enhancing search by stock name)。
重要檔案架構說明
stock-data-pipeline/
├── data/ # 資料庫的 Volume 綁定目錄
├── src/
│ ├── crawler/ # 爬取資料的模組
│ │ ├── scraping/ # 爬取資料的腳本
│ │ ├── Dockerfile # 構建爬蟲容器的 Dockerfile
│ │ ├── main.py # 爬蟲的入口點 (Entrypoint)
│ ├── dashboard/ # 資料視覺化儀表板
│ │ ├── service.py # UI 與資料庫之間的邏輯層
│ │ ├── main.py # UI 介面 (Entrypoint)
│ │ ├── Dockerfile # 構建儀表板容器的 Dockerfile
│ ├── database/ # 資料庫相關操作
│ │ ├── migrate/ # Alembic 資料庫遷移腳本
│ │ ├── repository/ # 以 Repository Pattern 封裝的 DB 操作
│ │ ├── db_helper.py # 資料庫相關設定
│ │ ├── model.py # 資料表欄位定義
│ │ ├── alembic.ini # Alembic 設定檔
├── .env.sample # .env 設定範例
├── docker-compose.yml # Docker Compose 設定檔
├── pyproject.toml # Python 套件管理設定
台灣集中保管結算所 (TDCC) 買賣日報表查詢系統 (TWSE)
⚠ 聲明 (Disclaimer) 本專案僅供學習用途,股票投資有風險,買賣需審慎評估,本專案不對任何投資行為負責。
This project is for educational purposes only. Stock investments involve risks. We do not take responsibility for any investment decisions.