Chuyển HTML sang văn bản thuần online miễn phí
Bỏ thẻ HTML hoặc lấy nội dung từ URL trang web thành văn bản thuần dễ đọc, giữ xuống dòng, kèm số từ và số ký tự.
Kết quả
Bấm “Chạy” để xem kết quả.
Gửi HTML qua trường html (JSON, form hoặc query string), dưới dạng body thô text/html, hoặc truyền một url công khai để API tự tải. API loại bỏ nội dung script, style, noscript, template và head, chuyển <br> cùng các thẻ khối (đoạn văn, tiêu đề, mục danh sách, hàng bảng, div...) thành xuống dòng, gộp khoảng trắng thừa và trả về văn bản kèm số characters và words.
Khác với API HTML sang Markdown, kết quả không giữ định dạng: đây là văn bản thuần, phù hợp để đánh chỉ mục tìm kiếm, tạo đoạn xem trước, gửi SMS hoặc email dạng text.
Giới hạn: HTML tối đa 5 MB (body request tối đa 6 MB); URL được tải tối đa 5 MB, timeout 10 giây, tối đa 8 lần chuyển hướng. Chỉ chấp nhận host http/https công khai.
Dùng trong code của bạn
curl -X POST "https://apibox.io.vn/v1/html-to-text" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html":"<h1>Order confirmed</h1><p>Thanks for your order, <b>Alice</b>.<br>It ships tomorrow.</p><ul><li>1 x Keyboard</li><li>2 x Mouse</li></ul><style>p{color:red}</style>"}'const res = await fetch('https://apibox.io.vn/v1/html-to-text', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"html": "<h1>Order confirmed</h1><p>Thanks for your order, <b>Alice</b>.<br>It ships tomorrow.</p><ul><li>1 x Keyboard</li><li>2 x Mouse</li></ul><style>p{color:red}</style>"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/html-to-text",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"html": "<h1>Order confirmed</h1><p>Thanks for your order, <b>Alice</b>.<br>It ships tomorrow.</p><ul><li>1 x Keyboard</li><li>2 x Mouse</li></ul><style>p{color:red}</style>"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/html-to-text');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"html":"<h1>Order confirmed</h1><p>Thanks for your order, <b>Alice</b>.<br>It ships tomorrow.</p><ul><li>1 x Keyboard</li><li>2 x Mouse</li></ul><style>p{color:red}</style>"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Tài liệu API → Nhận API key miễn phí
Hỏi đáp
Các dòng có được giữ nguyên không?
Có. <br> và các thẻ khối như p, div, li, tiêu đề, hàng bảng đều tạo dòng mới; từ ba dòng trống trở lên được gộp lại.
Nội dung JavaScript và CSS có bị loại bỏ không?
Có. Các thẻ script, style, noscript, template và head bị xoá trước khi lấy văn bản.
Có lấy text trực tiếp từ URL được không?
Được. Gửi url thay vì html, API sẽ tải trang (tối đa 5 MB) rồi chuyển đổi.