D4Vinci/Scrapling · error · ValueError
Unknown extraction type: {extraction_type}
Error message
Unknown extraction type: {extraction_type} What it means
_extract_content validates extraction_type against the values of Convertor._extension_map (markdown/html/text-family) before dispatching via a match statement. An empty string or a value not in the map raises ValueError rather than falling through silently. This mirrors the CLI's file-extension driven types.
Source
Thrown at scrapling/core/shell.py:628
if element.text:
element.text = _CONTROL_CHARS_PATTERN.sub("", _ZWC_PATTERN.sub("", element.text))
if element.tail:
element.tail = _CONTROL_CHARS_PATTERN.sub("", _ZWC_PATTERN.sub("", element.tail))
return Selector(root=clean_root, url=page.url, keep_comments=False)
@classmethod
def _extract_content(
cls,
page: Selector,
extraction_type: extraction_types = "markdown",
css_selector: Optional[str] = None,
main_content_only: bool = False,
) -> Generator[str, None, None]:
"""Extract the content of a Selector"""
if not page or not isinstance(page, Selector): # pragma: no cover
raise TypeError("Input must be of type `Selector`")
elif not extraction_type or extraction_type not in cls._extension_map.values():
raise ValueError(f"Unknown extraction type: {extraction_type}")
else:
if main_content_only:
page = cast(Selector, page.css("body").first) or page
page = cls._strip_noise_tags(page)
page = cls._sanitize_for_ai(page)
pages = [page] if not css_selector else cast(Selectors, page.css(css_selector))
for page in pages:
match extraction_type:
case "markdown":
yield cls._convert_to_markdown(page.html_content)
case "html":
yield page.html_content
case "text":
txt_content = page.get_all_text(
strip=True, ignore_tags=("script", "style", "noscript", "svg", "iframe")
)
for s in (View on GitHub (pinned to 5d213a2d47)
Solutions
- Use one of the exact values: 'markdown', 'html', or the text type defined in _extension_map
- Check Convertor._extension_map for the accepted set if unsure
- Prefer the public write_content_to_file with the right file extension, which maps the type for you
Example fix
# before Convertor._extract_content(page, 'md') # after Convertor._extract_content(page, 'markdown')
Defensive patterns
Strategy: validation
Validate before calling
valid_types = set(Convertor._extension_map.values()) extraction_type = extraction_type if extraction_type in valid_types else 'markdown'
Type guard
from typing import Any
def is_extraction_type(value: Any) -> bool:
return isinstance(value, str) and value in {'markdown', 'html', 'text'} Prevention
- Pass full type names ('markdown'), not file extensions ('md')
- Derive the type from write_content_to_file's extension map instead of hardcoding
When it happens
Trigger: Calling _extract_content with extraction_type='xml', 'json', '' or a typo like 'md' or 'Markdown' (case matters). The CLI only passes values derived from the output file extension (.md/.html/.txt), so this mostly bites direct callers.
Common situations: Passing a file extension ('md') instead of the type name ('markdown'), or assuming formats beyond the three supported ones exist.
Related errors
- Input must be of type `Selector`
- Filename must be provided
- Unknown file type: filename must end with '.md', '.html', or
- 'quality' is only valid when 'image_type' is 'jpeg'.
- Curl arguments parsing error: {message}
AI-assisted analysis of D4Vinci/Scrapling@5d213a2d47 (2026-08-14).
Data as JSON: /api/errors/9c40db705d6a641a.
Report an issue: GitHub.