MinerU-HTML is an intelligent HTML main content extraction tool based on Large Language Models (LLM). It can accurately identify and extract main content from complex web page HTML, automatically filtering out auxiliary elements such as navigation bars, advertisements, and metadata.
โจ Features
๐ฏ
LLM-Powered Extraction
: Uses state-of-the-art language models to intelligently identify main content
โก
Compact Format
: Now use compact format for the model instead of the original JSON format for faster inference speed
๐
Complete Processing Pipeline
: Includes HTML simplification, prompt construction, LLM inference, result parsing, main content extraction, and other complete processes
๐
Multiple Inference Backend Support
: Supports three inference backends: VLLM, Transformers, and OpenAI API
๐ก๏ธ
Fault Tolerance
: Supports fallback mechanism (trafilatura or bypass) to ensure content extraction even when processing fails
๐
Modular Design
: Clear architecture design, easy to extend and customize
๐งช
Complete Testing
: Includes comprehensive unit tests and integration tests
from mineru_html import MinerUHTML, MinerUHTMLConfig
# Create configuration
config = MinerUHTMLConfig(
use_fall_back='trafilatura', # or 'bypass'
prompt_version='compact', # recommend using compact
early_load=True
)
# Initialize MinerUHTML (using local model)
extractor = MinerUHTML(
model_path='path/to/your/model', # The model used must correspond to the prompt_version in MinerUHTMLConfig
config=config
)
# Process single HTML
html_content = '<html>...</html>'
result = extractor.process(html_content)
print(result[0].main_html)
# Process multiple HTML
html_list = ['<html>...</html>', '<html>...</html>']
results = extractor.process(html_list)
for result in results:
print(result.main_html)
print(result.case_id)
Using OpenAI API Backend
from mineru_html import MinerUHTML_OpenAI, MinerUHTMLConfig
# Create configuration
config = MinerUHTMLConfig(
use_fall_back='trafilatura',
prompt_version='v2', # Recommend using v2
early_load=True
)
# Initialize MinerUHTML_OpenAI
extractor = MinerUHTML_OpenAI(
base_url='https://api.openai.com/v1',
sk='your-api-key',
model='gpt-5',
config=config,
retry_times=3
)
# Process HTML
html_content = '<html>...</html>'
result = extractor.process(html_content)
print(result[0].main_html)
Using Transformers Backend
from mineru_html import MinerUHTML_Transformers, MinerUHTMLConfig
# Create configuration
config = MinerUHTMLConfig(
use_fall_back='trafilatura',
prompt_version='v2',
early_load=True
)
# Initialize MinerUHTML_Transformers
extractor = MinerUHTML_Transformers(
model_path='path/to/your/model', # The model used must correspond to the prompt_version in MinerUHTMLConfig
config=config,
model_init_kwargs={
'device_map': 'auto',
'dtype': 'auto',
},
model_gen_kwargs={
'max_new_tokens': 8192,
}
)
# Process HTML
html_content = '<html>...</html>'
result = extractor.process(html_content)
print(result[0].main_html)
๐ Core Concepts
Processing Pipeline
The MinerU-HTML processing pipeline includes the following steps:
HTML Simplification
(
simplify_html
): Simplifies raw HTML into a structured format, assigning a unique
_item_id
attribute to each element
Prompt Construction
(
build_prompt
): Constructs LLM prompts based on simplified HTML to guide the model in content classification
LLM Inference
(
inference
): Uses LLM to classify each element, marking them as "main" (main content) or "other" (auxiliary content)
Result Parsing
(
parse_result
): Parses the classification results returned by LLM
Main Content Extraction
(
extract_main_html
): Extracts main content from original HTML based on classification results
Fallback Processing
: If the above process fails, uses fallback mechanism (trafilatura or bypass) for content extraction
Configuration Options
MinerUHTMLConfig
supports the following configurations:
use_fall_back
: Fallback type, optional
'trafilatura'
or
'bypass'
early_load
: Whether to load the model early (default
True
)
prompt_version
: Prompt version, optional
'v2'
,
'compact'
. The MinerUHTML interface and MinerUHTML_Transformers interface can use
'compact'
, the MinerUHTML_OpenAI interface can use
'v2'
Usage instructions for different prompt_version:
'compact'
: Used for local model inference, it returns more concise results (only keeping the key and value in the JSON dictionary). It is recommended to use the
'compact'
model for faster inference speed.
'v2'
: Used for OpenAI API inference, it is the result after prompt optimization.
๐ง Advanced Usage
Using Factory Functions to Create Backends
You can also directly use factory functions to create backends and then pass them to
MinerUHTMLGeneric
:
from mineru_html import MinerUHTMLGeneric, MinerUHTMLConfig
from mineru_html.inference.factory import create_vllm_backend, create_openai_backend, create_transformers_backend
# Create VLLM backend using factory function
llm = create_vllm_backend(
model_path='path/to/model',
response_format='compact',
max_context_window=32 * 1024,
model_init_kwargs={'tensor_parallel_size': 1}
)
# Create Transformers backend using factory function
llm = create_transformers_backend(
model_path='path/to/model',
max_context_window=32 * 1024,
model_init_kwargs={
'device_map': 'auto',
'dtype': 'auto',
},
model_gen_kwargs={
'max_new_tokens': 8192,
}
)
# Create OpenAI backend using factory function
llm = create_openai_backend(
base_url='https://api.openai.com/v1',
sk='your-api-key',
model='gpt-5',
max_context_window=128 * 1000
)
# Use the created backend
config = MinerUHTMLConfig()
extractor = MinerUHTMLGeneric(llm=llm, config=config)
Error Handling
from mineru_html.exceptions import MinerUHTMLError
try:
result = extractor.process(html_content)
except MinerUHTMLError as e:
print(f"Processing failed: {e}")
print(f"Case ID: {e.case_id}")
Backend Selection Recommendations
VLLM Backend
(
MinerUHTML
): Suitable for local deployment, requires GPU, best performance
Transformers Backend
(
MinerUHTML_Transformers
): Suitable for local deployment, supports CPU/GPU, high flexibility
OpenAI API Backend
(
MinerUHTML_OpenAI
): Suitable for cloud services, no local model required, simple to use
๐งช Testing
Run unit tests and integration tests:
pytest tests/
Runs of opendatalab MinerU-HTML-v1.1-compact on huggingface.co
0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About MinerU-HTML-v1.1-compact huggingface.co Model
MinerU-HTML-v1.1-compact huggingface.co
MinerU-HTML-v1.1-compact huggingface.co is an AI model on huggingface.co that provides MinerU-HTML-v1.1-compact's model effect (), which can be used instantly with this opendatalab MinerU-HTML-v1.1-compact model. huggingface.co supports a free trial of the MinerU-HTML-v1.1-compact model, and also provides paid use of the MinerU-HTML-v1.1-compact. Support call MinerU-HTML-v1.1-compact model through api, including Node.js, Python, http.
MinerU-HTML-v1.1-compact huggingface.co is an online trial and call api platform, which integrates MinerU-HTML-v1.1-compact's modeling effects, including api services, and provides a free online trial of MinerU-HTML-v1.1-compact, you can try MinerU-HTML-v1.1-compact online for free by clicking the link below.
opendatalab MinerU-HTML-v1.1-compact online free url in huggingface.co:
MinerU-HTML-v1.1-compact is an open source model from GitHub that offers a free installation service, and any user can find MinerU-HTML-v1.1-compact on GitHub to install. At the same time, huggingface.co provides the effect of MinerU-HTML-v1.1-compact install, users can directly use MinerU-HTML-v1.1-compact installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
MinerU-HTML-v1.1-compact install url in huggingface.co: