文件 · DOCUMENTATION

tw-lvr-cli 使用文件v1

tw-lvr-cli documentationv1

把內政部實價登錄的公開資料,用一行指令轉成乾淨、帶型別的 JSON/CSV,寫到磁碟給程式、後端與 agent 使用。以下為安裝、指令、輸出欄位與整合方式。與內政部無關。

Turn MOI's public real-price registry data into clean, typed JSON/CSV with one command — written to disk for programs, backends and agents. Below: install, commands, output fields and integration. Unaffiliated with MOI.

本頁目錄On this page
01 · 安裝

安裝 Install

Install 安裝

用 npm 或 bun 全域安裝。安裝後另需執行一次 Playwright 的 headless Chromium 下載——這是唯一的非 JavaScript 相依套件。

Install globally with npm or bun. After installing, run Playwright's headless Chromium download once — this is the only non-JavaScript dependency.

全域安裝Global install
$ npm i -g tw-lvr-cli
# 或使用 bun
$ bun add -g tw-lvr-cli
必要:headless Chromium(約 190MB)Required: headless Chromium (~190MB)
$ npx playwright install chromium-headless-shell
註 · NOTE

若缺少 headless Chromium,CLI 會以結束代碼 6ERR_ENV)退出,並印出上面的安裝指令。

If headless Chromium is missing, the CLI exits with code 6 (ERR_ENV) and prints the install command above.

不想全域安裝?單次執行

No global install? One-off run

npx
$ npx -y tw-lvr-cli@latest extract --where "新竹市東區關新路" --from 2024 --to 2026 --top 3 --pretty
02 · 快速開始

快速開始 Quick start

Quick start 快速開始

指定地址、年份範圍與筆數即可取得結果。--pretty 會輸出排版過的 JSON。

Pass an address, a year range and a count to get results. --pretty prints formatted JSON.

第一個查詢Your first query
$ tw-lvr extract --where "新竹市東區關新路" --from 2024 --to 2026 --top 3 --pretty
註 · NOTE

最新一筆交易永遠排在最前面。加上 --out result.json 會把資料寫到磁碟——資料因此不會進入模型的 context。

The latest record is always sorted first. Adding --out result.json writes the data to disk — so it never enters the model context.

寫到磁碟Write to disk
$ tw-lvr extract --where "新竹市東區關新路" --from 2024 --to 2026 --out result.json
# → result.json · 資料留在磁碟,不進 context
03 · 指令與參數

指令與參數 Commands & flags

Commands & flags 指令與參數

主要指令是 extract,完整簽章如下:

The main command is extract. Full signature:

tw-lvr extract
tw-lvr extract --where <地址> --from <YYYY> --to <YYYY>
       [--refine] [--ptype 1,2] [--query biz|sale | --presale]
       [--top N | --limit N] [--community <社區名>]
       [--out <檔案|資料夾>] [--format json|csv] [--pretty]

參數說明

Flag reference

Flag說明Description
--where <地址>查詢地址(必填)Address to query (required)
--from / --to年份範圍(YYYY)Year range (YYYY)
--refine加上調整後單價、排除旗標與 confidenceAdds adjusted unit price, exclusion flags & confidence
--ptype 1,2依物件類型代碼篩選Filter by property-type codes
--query biz|sale查詢類別,預設 biz(成屋買賣)Query category, default biz (completed-home sales)
--presale改查預售屋Switch to presale units
--top N | --limit N限制回傳筆數Cap the number of records returned
--community <社區名>依社區名稱篩選Filter by community name
--out <檔案|資料夾>寫入磁碟(檔案或資料夾)Write to disk (file or folder)
--format json|csv輸出格式,預設 jsonOutput format, default json
--pretty輸出排版過的 JSONPretty-print the JSON

其他指令

Other commands

輔助Helpers
$ tw-lvr glossary     # 列出完整欄位與詞彙表
$ tw-lvr --help       # 指令說明
$ tw-lvr --version    # 版本
註 · NOTE

預設為 --query biz(成屋買賣);--presale 會切換到預售屋。資料量大或年份跨度長時,請切成每段 5 年以內 分批查詢,否則過大的回應會以 ERR_NETWORK 失敗。

Default is --query biz (completed-home sales); --presale switches to presale units. For large or long ranges, split into chunks of 5 years or less — an oversized response fails with ERR_NETWORK.

04 · 輸出欄位

輸出欄位 Output fields

Output fields 輸出欄位

每筆交易的核心欄位如下。完整欄位清單請執行 tw-lvr glossary

Core fields per transaction below. For the full list, run tw-lvr glossary.

Field欄位Meaning
building建物建物名稱Building name
address地址地址Address
txnDateRoc交易日期交易日期(民國)Transaction date (ROC calendar)
totalPriceWan總價總價(萬元)Total price (10k TWD / 萬元)
siteAdjUnitPrice調整後單價調整後單價Adjusted unit price
totalAreaPing坪數總坪數Total area (ping / 坪)
layout格局房廳衛格局Room layout
註 · NOTE

--refine 會額外加上排除旗標(親友/純車位/非住宅)與每筆的 confidenceconfidence 是資料品質旗標,不是估價。

--refine adds exclusion flags (related-party / parking-only / non-residential) and a per-record confidence. Confidence is a data-quality flag, not a valuation.

05 · 結束代碼

結束代碼 Exit codes

Exit codes 結束代碼

指令以下列結束代碼退出,方便在腳本與 CI 中判斷。

The command exits with these codes, for branching in scripts and CI.

Code意義Meaning
0成功或無資料Success, or no data
2輸入錯誤Invalid input
3網站改版Source site changed
4網路Network error
5被限流Rate limited
6環境或瀏覽器Environment / browser
7部分成功Partial success
06 · 架構

架構 Architecture

Architecture 架構

每次查詢經過四個階段。

Each query passes through four stages.

01Resolve
地址加年份解析成查詢參數。
Parse address + year range into query parameters.
02Fetch
啟動短暫的 headless Chromium,擷取官網原始交易列。
Launch a transient headless Chromium and scrape the raw transaction rows from the official site.
03Normalize
原始列轉成乾淨、帶型別的資料,統一欄位名稱、單位(坪/萬元)與民國日期。
Turn raw rows into clean, typed data — unifying field names, units (ping / 萬元) and ROC dates.
04Refine --refine
(僅在 --refine 時)加上調整後單價、排除旗標與 confidence。
(Only with --refine) add adjusted unit price, exclusion flags and confidence.
07 · Library API

Library API 當函式庫使用

Library API use as a library

同一個引擎可以直接 import。匯出 extractextractRefined,型別定義在 src/index.ts

The same engine is importable. It exports extract and extractRefined; types live in src/index.ts.

TypeScript
import { extract, extractRefined } from 'tw-lvr-cli';
import type { CleanRawRecord } from 'tw-lvr-cli';

const res = await extract({
  where: '新竹市東區關新路',
  from: '2024', to: '2026',
});
const records: CleanRawRecord[] = res.data ?? [];

// extract 回傳 Result;資料在 res.data
console.log(records[0]?.totalPriceWan);

// 需要調整後單價與旗標時,改用 extractRefined()
08 · 當 plugin 用

當 plugin 用 Use as a plugin

Use as a plugin 當 plugin 用

可安裝進 Claude Code 與 Codex,讓 agent 直接呼叫 CLI。

Install into Claude Code and Codex so an agent can call the CLI directly.

Claude Code
/plugin marketplace add felixfu824/taiwan-property-price-cli
/plugin install tw-lvr-cli@tw-lvr-cli
Codex
$ codex plugin marketplace add felixfu824/taiwan-property-price-cli
$ codex plugin add tw-lvr-cli@tw-lvr-cli
註 · NOTE

plugin 內含一份 Agent Skill(SKILL.md),告訴 agent 何時以及如何呼叫這個 CLI。

The plugin bundles an Agent Skill (SKILL.md) that tells the agent when and how to call the CLI.

09 · 給 AI agent

給 AI agent For AI agents

For AI agents 給 AI agent

agent 應該把 tw-lvr 當成 shell 指令執行,並從 --out 指定的檔案讀取 JSON/CSV,而不是把資料讀進 context。結果是確定性的,每次查詢約 2 秒。

An agent should run tw-lvr as a shell command and read the JSON/CSV from the --out file, instead of pulling it into context. Results are deterministic, about 2s per query.

本站也提供機器可讀的參考檔:/llms.txt/facts

The site also serves machine-readable references: /llms.txt and /facts.

10 · 資料與授權

資料與授權 Data & license

Data & license 資料與授權

資料來源為內政部不動產實價登錄開放資料,採政府資料開放授權條款(OGDL,可轉 CC BY 4.0),須標示來源為內政部,資料依法去識別化。程式碼以 Apache-2.0 授權。

Data comes from the MOI real-price registry open data under the Open Government Data License (OGDL, compatible with CC BY 4.0); the source must be attributed to MOI and the data is de-identified by law. The code is licensed Apache-2.0.

隱私

Privacy

  • 本機執行,無 telemetry,不蒐集個資。
  • Runs locally, no telemetry, collects no personal data.
  • 僅寫入 --out 指定的路徑。
  • Writes only to the path given in --out.
  • 對外請求僅限 lvr.land.moi.gov.tw
  • Outbound requests are limited to lvr.land.moi.gov.tw.
註 · NOTE

本工具與內政部無任何關係,按現狀(as-is)提供。

This tool is unaffiliated with MOI and is provided as-is.

11 · 疑難排解

疑難排解 Troubleshooting

Troubleshooting 疑難排解

症狀Symptom處理Fix
chrome-headless-shell 未安裝chrome-headless-shell not installed exit 6 → 執行安裝指令 npx playwright install chromium-headless-shell exit 6 → run npx playwright install chromium-headless-shell
回應過大Response too large 分段查詢(每次 5 年以內) Split into chunks of 5 years or less
被限流Rate limited exit 5 → 稍後再試 exit 5 → try again later
網站改版Source site changed exit 3 → 回報 issue exit 3 → file an issue
需要協助 · HELP

仍有問題?到 GitHub Issues 回報。

Still stuck? Open a report on GitHub Issues.