CSV の中にある HTML のタグの閉じ忘れを、自動で直すツールです。 ファイルのパスを貼り付けて Enter を押すだけ。むずかしい知識は不要で、 元のファイルは書き換えません(直したものは別名で保存します)。 Python だけで動き、追加のインストールは何も要りません。
🇬🇧 English version is at the bottom of this page — jump to English ↓.
言語 / Languages: 日本語(はじめての方へ) · English
ネットショップの商品データ(CSV)には、商品説明が HTML で書かれていることがあります。
その HTML で タグが閉じられていない(例:<b> を書いたのに </b> が無い)と、
出品先(楽天市場、Yahoo!ショッピング等)でエラーになることがあります。
csv-html-fixer は、CSV を読み込んで、こうした閉じ忘れを自動で直します。
- ✅ 質問に答えるだけ — ファイルのパスを貼り付けて Enter。
- ✅ 元のファイルは無事 — 直した結果は
〇〇_fixed.csvという別名で保存します。 - ✅ 必要な所だけ直す — 正しく書けているセルは一切変更しません。
- ✅ 文字化けしにくい — Shift-JIS(cp932)/ UTF-8 を自動判定し、同じ文字コードで保存します。
- ✅ インストール不要 — Python さえあれば、ファイル 1 つで動きます。
直すのはこんな所です:
<p>説明文。<b>太字が閉じられていない → <p>説明文。<b>太字が閉じられていない</b></p>
<div>本文</div></div>(閉じタグが多い) → <div>本文</div>
<p><a href="...">リンク</p>(交差) → <p><a href="...">リンク</a></p>
手順1は最初の一度だけ。次回からは手順2・3だけです。
このツールは Python(無料)で動きます。多くの Mac には最初から入っています。
確認するには、ターミナル(→手順2)でこう入力して Enter:
python3 --versionPython 3.11.6 のような数字が出れば準備完了です(3.8 以上ならOK)。
出てこない場合は https://www.python.org/downloads/ から「Download」ボタンで入れて、
画面の指示どおり進めてください(初期設定のままでOK)。
「ターミナル」はコマンドを入力する窓です。
- macOS …
⌘+Space→「ターミナル」と入力して Enter - Windows …
⊞(Windows)キー →「ターミナル」または「PowerShell」と入力して Enter - Linux …
Ctrl+Alt+T
-
このリポジトリの
csv_html_fixer.pyをダウンロードします (ページ右上の緑の「Code」→「Download ZIP」でも、ファイルを開いて保存でもOK)。 -
ターミナルで次のように入力して Enter(
csv_html_fixer.pyの部分は、保存した ファイルをターミナルにドラッグ&ドロップするとパスが入ります):python3 csv_html_fixer.py
-
次のように聞かれるので、直したい CSV ファイルをターミナルにドラッグ&ドロップして Enter を押します(Windows は、ファイルを右クリック →「パスのコピー」して貼り付け):
============================================================ csv-html-fixer v1.0.0 CSV 内の HTML タグの閉じ忘れを自動で直します ============================================================ 修正したい CSV ファイルを、この画面にドラッグ&ドロップするか、 パスを貼り付けて Enter を押してください。(何も入力せず Enter で終了) CSV のパス> /Users/you/Downloads/items.csv -
直し終わると、結果と保存先が表示されます:
=== 結果 === 入力 : /Users/you/Downloads/items.csv 文字コード: cp932 修復セル数: 3 修復したセル: 行3 列「description」 補完: </b>,</p> 除去: - 行4 列「description」 補完: - 除去: </div> 出力 : /Users/you/Downloads/items_fixed.csv ※ 元のファイルはそのまま残しています(非破壊)。
直った CSV は、元のファイルと同じフォルダに 〇〇_fixed.csv という名前で保存されます。
そのまま出品先に再アップロードしてください。
「元のデータは壊れませんか?」
壊れません。このツールは元のファイルを書き換えず、別名(_fixed.csv)で新しく保存します。
心配な場合は、念のため元ファイルのコピーを取ってから実行してください。
ファイルのパスがうまく入りません
- macOS / Linux … ファイルをターミナルの窓にドラッグ&ドロップするとパスが入ります。
- Windows … ファイルを**右クリック →「パスのコピー」**で貼り付けてください。
- 手で打つ場合、パスに空白が含まれていると失敗しやすいです。引用符
" "で囲むか、上の方法を使ってください。
「command not found: python3」と出ます
Python が入っていません。https://www.python.org/downloads/ から入れてください。
Windows では python3 の代わりに python で動くこともあります。
文字化けします / 文字コードを指定したい
通常は自動で判定します。うまくいかないときは、文字コードを明示できます:
python3 csv_html_fixer.py items.csv --encoding cp932たくさんのファイルを自動で処理したい
ファイルのパスを引数で渡すと、質問されずにそのまま実行します(バッチ処理向け):
python3 csv_html_fixer.py items.csv
python3 csv_html_fixer.py items.csv --out fixed.csv --encoding cp932試してみたい方へ:このリポジトリの
examples/sample.csvで動作を確認できます。python3 csv_html_fixer.py examples/sample.csv
Automatically fix unclosed HTML tags inside CSV cells — just paste the path to your CSV and press Enter. No technical skills required. Your original file is never modified (the fixed result is saved under a new name). Runs on Python only, with zero dependencies.
🇯🇵 日本語のガイドはこのページ上部にあります → 日本語(はじめての方へ)↑.
E-commerce product CSVs often contain HTML descriptions. When a tag is left unclosed
(e.g. a <b> with no </b>), marketplaces such as Rakuten or Yahoo! Shopping reject the
listing. csv-html-fixer reads the CSV and repairs those problems with minimal edits —
cells that are already valid are left byte-for-byte unchanged.
| Problem | Before | After |
|---|---|---|
| Missing close tag | <p>text<b>bold |
<p>text<b>bold</b></p> |
| Stray/extra close tag | <div>x</div></div> |
<div>x</div> |
| Mis-nesting | <p><a href="...">link</p> |
<p><a href="...">link</a></p> |
No installation needed — it's a single standard-library script. Download
csv_html_fixer.py and run it with Python 3.8+.
Optionally, install it as a command with pipx:
pipx install . # from a clone of this repo
csv-html-fixer # then run the command anywhere# Interactive (asks for the CSV path):
python3 csv_html_fixer.py
# Direct / for automation:
python3 csv_html_fixer.py input.csv
python3 csv_html_fixer.py input.csv --out fixed.csv --encoding cp932| Option | Default | Description |
|---|---|---|
csv (positional) |
(asks interactively) | Path to the CSV to fix |
--out PATH |
<name>_fixed.csv |
Output path |
--encoding ENC |
auto (utf-8-sig / utf-8 / cp932) |
Force a character encoding |
--version |
Print version | |
--help |
Show help |
- Encoding & format are detected from the raw bytes — UTF-8 (with/without BOM) or Shift-JIS (cp932), plus the newline style (CRLF/LF) and whether the file ends with a newline. All of these are reproduced exactly on output.
- Every cell is scanned. A cell is processed only if it contains a known HTML tag, so
plain text like
a < b > cis never touched. - A stack-based repair walks the tags: opening tags are pushed; a closing tag pops its match (closing any mis-nested elements in between with synthesized tags); a closing tag with no matching open is dropped as stray; anything still open at the end is closed in LIFO order. Correct markup passes through unchanged, so balanced cells are exact no-ops.
- The result is written with Python's
csvmodule (preserving quoting and in-field newlines) in the same encoding as the input, to a new file.
Inserted close tags are pure ASCII, so they are safe in any supported encoding. The tag
tokenizer tolerates > inside quoted attribute values (e.g. <a title="a>b">).
No third-party dependencies — just Python 3.8+.
git clone https://github.com/ECgear/csv-html-fixer.git
cd csv-html-fixer
python3 -m unittest discover -s tests -v # run the tests
python3 csv_html_fixer.py examples/sample.csvContributions welcome — see CONTRIBUTING.md and CODE_OF_CONDUCT.md. Security reports: see SECURITY.md.
MIT © ECgear
Built with the Python standard library only — no third-party dependencies. Thanks to everyone who reports broken-CSV samples that make the repair logic more robust.