文件 · DOCUMENTATION

tw-lvr-cli 使用文件v0.2.0

tw-lvr-cli documentationv0.2.0

把內政部實價登錄的公開資料,用一行指令轉成乾淨、帶型別的 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 · or use 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 202401 --to 202612 --top 3 --pretty
02 · 快速開始

快速開始 Quick start

Quick start 快速開始

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

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

第一個查詢Your first query
$ tw-lvr extract --where "新竹市東區關新路" --from 202401 --to 202612 --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 202401 --to 202612 --out result.json
# → result.json · 資料留在磁碟,不進 context · data stays on disk, out of context
03 · 指令與參數

指令與參數 Commands & flags

Commands & flags 指令與參數

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

The main command is extract. Full signature:

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

參數說明

Flag reference

Flag說明Description
--where <地址>查詢地址(必填)Address to query (required)
--from / --to月份範圍(YYYYMM)Month range (YYYYMM)
--refine加上調整後單價、排除旗標與 confidenceAdds adjusted unit price, exclusion flags & confidence
--ptype <codes>依物件類型代碼篩選。買賣預設 1,2(房地);3 土地、4 建物、5 車位。租賃預設 1,2,3,4,5,6,7——6/7 為 112/09 新制的建物租賃,覆寫時至少保留一個 1–5 代碼Filter by property-type codes. Sale default 1,2 (house+land); 3 land, 4 building, 5 parking. Rent default 1,2,3,4,5,6,7 — 6/7 carry post-2023-09 new-form building leases; keep at least one 1–5 code when overriding
--query biz|sale|rent查詢類別,預設 biz(成屋買賣);sale 預售屋;rent 租賃Query category, default biz (completed-home sales); sale = presale; rent = rental
--presale改查預售屋Switch to presale units
--rent改查租賃(租賃結構;路名在本地過濾;日期區間拉寬並看 coverage 逐年筆數)Switch to rental (lease schema; road filtered client-side; widen dates & check the coverage line)
--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     # 列出完整欄位與詞彙表 · full field glossary
$ tw-lvr --help       # 指令說明 · command help
$ tw-lvr --version    # 版本 · version
註 · NOTE

預設為 --query biz(成屋買賣);--presale 會切換到預售屋;--rent 切換到租賃(輸出為租賃結構,欄位見 tw-lvr glossary --rent;租賃資料逐年連續、更新到當月,先看 stderr 的 coverage: 逐年筆數再談趨勢)。資料量大或月份跨度長時,請切成每段 60 個月以內 分批查詢,否則過大的回應會以 ERR_NETWORK 失敗。

Default is --query biz (completed-home sales); --presale switches to presale units; --rent switches to rental (lease output schema — see tw-lvr glossary --rent; rental coverage is continuous and current — check the per-year coverage: stderr line before trending). For large or long ranges, split into chunks of 60 months 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.

租賃 · RENT

--rent 回傳獨立的租賃結構,不是買賣欄位:monthlyRentTwd(月租金,非萬)、unitRentTwdPing(元/坪/月)、rentTarget(租賃標的)、hasMgmtOrghasFurniture(管理組織/附傢俱)、rentPeriod(租期);2023-09 新版申報書之後的案件另有 rentalType(出租型態)、rentalService(租賃住宅服務——社會住宅* 為補貼案件,做市場行情請先剔除)、hasElevatorequipment。完整欄位:tw-lvr glossary --rent。租賃資料逐年連續、更新到當月;先看 stderr 的 coverage: 逐年筆數再談趨勢(跨 2023-09 的變化含申報主體改變的成分)。查詢帶路名時由 CLI 在本地過濾到該路段(政府網站的租賃查詢只到行政區層級,stderr 會註明筆數)。

--rent returns a separate lease schema, not the sale fields: monthlyRentTwd (monthly rent, in TWD not 萬), unitRentTwdPing (TWD/ping/month), rentTarget, hasMgmtOrg/hasFurniture, rentPeriod; leases signed after the Sep-2023 reporting-form change also carry rentalType, rentalService (社會住宅* values are subsidized social housing — drop for market-rate comps), hasElevator, equipment. Full dictionary: tw-lvr glossary --rent. Rental coverage is continuous and current; check the per-year coverage: stderr line before reading trends (shifts across Sep 2023 are partly compositional — the reporter mix changed). A road in --where is filtered client-side for rent (the government site only resolves rentals to district level; stderr notes the counts).

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 + month 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: '202401', to: '202612',
});
const records: CleanRawRecord[] = res.data ?? [];

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

// Use extractRefined() for adjusted prices and flags/需要調整後單價與旗標時,改用 extractRefined()

首次查詢會啟動一個可重用的 headless 瀏覽器;閒置 15 秒後自動關閉,腳本會自行結束(LVR_BROWSER_IDLE_MS 可調)。要立即結束、或在常駐程式中自行控制關閉時機,呼叫 closeBrowser()

The first query launches one reusable headless browser; it closes itself after 15 seconds idle, so plain scripts exit on their own (tune with LVR_BROWSER_IDLE_MS). For immediate exit, or to own the shutdown in long-lived processes, call closeBrowser().

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–3 秒。

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 2–3s 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, convertible to 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 分段查詢(每次 60 個月以內) Split into chunks of 60 months 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.