Communitygithub.com

HTML to Text (HTMLテキスト変換)

標準ライブラリのみを使用してHTMLからプレーンテキストを抽出します(BeautifulSoup/lxml不要)。スクリプトやスタイルを削除し、ブロックタグを改行に変換し、空白を整理します。LLMに送る前にスクレイピングしたHTMLをクリーンにしたいときや、Webコンテンツからテキストインデックスを構築するときに使用します。

HTML to Text (HTMLテキスト変換) とは?

このスキルは、`html.parser.HTMLParser` を利用した軽量なHTMLプレーンテキスト変換ツールです。外部ライブラリ(BeautifulSoup, lxml)に依存せず、標準ライブラリだけで動作するため、環境構築が簡単で軽量です。`<script>` や `<style>` ブロックは完全に除去され、ブロック要素は改行に変換され、連続する空白や空行は圧縮されるため、出力は自然な散文として読みやすくなります。この変換により、LLM(大規模言語モデル)に送信するトークン数を削減できるほか、検索インデックス用のクリーンなテキストを生成できます。呼び出すタイミングとしては、ユーザーが「このHTMLからテキストを取り出して」「タグを除去して要約して」などと依頼した場合や、HTMLをそのままモデルに渡すとノイズになる場合です。ただし、テーブル構造やリンクをMarkdownとして保持したい場合や、JavaScriptでレンダリングされるページの場合は、本スキルは適しません(その場合はヘッドレスブラウザで取得後、専用コンバータを使用してください)。サポートプラットフォームはPython標準ライブラリ上で動作するため、Claude Code、Cursor、Codexなど、Pythonコードを実行できるあらゆるAIエージェントで利用可能です。

対応~Claude Code~Codex CLI~Cursor✓Gemini CLI
npx skills add https://github.com/baronguyen001/ai-automation-skills/tree/HEAD/skills/html-to-text

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

HTML からテキストへ

このスキルは、スクレイピングしたページ、ニュースレターの本文、フィードエントリのコンテンツなど、HTML形式のデータから、beautifulsoup4 や lxml を追加でインストールせずに、クリーンで読みやすいプレーンテキストを抽出したい場合に使用します。HTMLParser の小さなサブクラスが <script> や <style> を除去し、ブロック要素を改行に変換し、空白を整理します。これにより、LLMにコンテンツを送信する前(トークン数を削減)や、検索インデックスに投入する前に最適な形に整形できます。

呼び出すタイミング

  • ユーザーが「このHTMLからテキストを取り出して」「スクレイピングしたページをクリーンにして」「タグを除去してから要約して」「このメールHTMLをテキストに変換して」と依頼した場合。
  • HTMLをそのままモデルやダイジェストに入力しようとしており、マークアップが単なるノイズになっている場合。

呼び出さないほうが良いタイミング

  • 構造(テーブル、リンクをMarkdown形式など)を保持する必要がある場合 — その場合は本格的なHTML-to-Markdownコンバータを使用してください。
  • ページがJavaScriptでレンダリングされている場合 — まずヘッドレスブラウザで取得し、その後に変換してください。

具体的な例

ユーザー入力:

この記事のHTMLをプレーンテキストに変換して、トークン数を減らして要約できるようにして。

出力:

# assets/htmltext.py をプロジェクトにコピーしてから、次のように使います:
from htmltext import html_to_text

text = html_to_text(article_html)
summary = call_llm(f"要約:\n{text}")

<script> と <style> ブロックは完全に除去され、ブロックタグは改行に変換され、連続するスペースや空行は圧縮されるため、出力は散文のように読めます。

適用すべきパターン

  1. html.parser.HTMLParser を convert_charrefs=True を指定してサブクラス化し、文字参照が自動的にデコードされるようにします。
  2. script、style、head タグのネスト深さを追跡するためのスキップ深度を管理し、それらのテキストが出力に漏れないようにします。
  3. ブロックタグの周囲に改行を挿入し、行内の連続する空白や複数行の空行を圧縮します。
  4. 純粋関数(文字列入力、文字列出力)を維持し、単体テストが簡単に行えるようにします。

参考:assets/htmltext.py。

ソース

作者のスクレイピングおよびダイジェストパイプラインから抽出しました。v1.0.0。 関連項目:[[rss-feed-reader]]、[[gemini-cost-tracker]]、[[pipeline-orchestrator]]。

→ Trawlkit を使って完全な実行可能ボットを構築してください。

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

baronguyen001/ai-automation-skills

Schedule any script to run on a recurring schedule on Windows (Task Scheduler) or Linux (cron) - register, list, and remove jobs from one command, with logging to a file and a guard against overlapping runs. Use for schedule a script, run nightly, set up a cron job, windows task scheduler, or run on a timer.

baronguyen001/ai-automation-skills

Turn a run's list of result dicts into a schema'd CSV and a Markdown table from one column spec - declare columns once, emit both, with stable ordering and safe escaping, stdlib only, no pandas. Use when the user asks to write results to CSV, export a report, make a markdown summary table, or save a run's output as a spreadsheet.

baronguyen001/ai-automation-skills

Persist records between scheduled runs as append-only JSON Lines (one object per line) with streaming reads and optional key-based dedup, stdlib only. Use when the user wants to log run results to JSONL, append events to a file, dedup records by id across runs, or keep a simple durable history without a database.

baronguyen001/ai-automation-skills

Extract text and simple table-like rows from a PDF for downstream AI without OCR binaries. Use when the user asks to read a PDF, turn a PDF into text, pull simple tables from statements/reports, or feed PDF content into an LLM pipeline.

baronguyen001/ai-automation-skills

Rotate a pool of HTTP/SOCKS proxies with round-robin selection, failure tracking, and a cooldown that benches dead proxies before retrying. BYO proxy list via env - none are shipped. Use for rotate proxies, spread requests across proxies, avoid IP bans, retry through a different proxy, or proxy health check.

baronguyen001/ai-automation-skills

Parse an RSS 2.0 or Atom feed into normalized item dicts (title, link, id, published, summary) with the standard library only - no feedparser. Use when the user asks to read an RSS/Atom feed, poll a blog/news feed, extract feed entries, or watch a site that publishes a feed.

baronguyen001/ai-automation-skills

Upload and download run artifacts from S3-compatible storage with BYO bucket and credentials from env. Use when the user asks to store scraper output, archive reports, publish artifacts to object storage, fetch a prior run file, or use MinIO/R2/Spaces/S3 without hardcoding credentials.

baronguyen001/ai-automation-skills

Draft a short-form TikTok/Reels/Shorts or long-form video script from a topic and creator persona file - hook variants, beat-structured body, CTA, b-roll cues, caption overlays, and [STORY]/[NUMBER] slots so the model never fabricates personal facts. Use for write a video script, tiktok script, youtube script, or /shortform-script.

baronguyen001/ai-automation-skills

Give scheduled scripts memory between runs with one SQLite file - a seen-set for dedup, a key/value cursor to resume where you left off, and order-preserving new-item filtering. Use for dedup across runs, don't re-alert the same item, remember the last id, resume a scraper, or persist state between cron runs.

関連スキル