{"record":{"id":"af71d182836512a4","repo":"D4Vinci/Scrapling","slug":"input-must-be-of-type-selector","errorCode":null,"errorMessage":"Input must be of type `Selector`","messagePattern":"Input must be of type `Selector`","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"scrapling/core/shell.py","lineNumber":626,"sourceCode":"            element.drop_tree()\n        for element in clean_root.iter():\n            if element.text:\n                element.text = _CONTROL_CHARS_PATTERN.sub(\"\", _ZWC_PATTERN.sub(\"\", element.text))\n            if element.tail:\n                element.tail = _CONTROL_CHARS_PATTERN.sub(\"\", _ZWC_PATTERN.sub(\"\", element.tail))\n        return Selector(root=clean_root, url=page.url, keep_comments=False)\n\n    @classmethod\n    def _extract_content(\n        cls,\n        page: Selector,\n        extraction_type: extraction_types = \"markdown\",\n        css_selector: Optional[str] = None,\n        main_content_only: bool = False,\n    ) -> Generator[str, None, None]:\n        \"\"\"Extract the content of a Selector\"\"\"\n        if not page or not isinstance(page, Selector):  # pragma: no cover\n            raise TypeError(\"Input must be of type `Selector`\")\n        elif not extraction_type or extraction_type not in cls._extension_map.values():\n            raise ValueError(f\"Unknown extraction type: {extraction_type}\")\n        else:\n            if main_content_only:\n                page = cast(Selector, page.css(\"body\").first) or page\n                page = cls._strip_noise_tags(page)\n                page = cls._sanitize_for_ai(page)\n\n            pages = [page] if not css_selector else cast(Selectors, page.css(css_selector))\n            for page in pages:\n                match extraction_type:\n                    case \"markdown\":\n                        yield cls._convert_to_markdown(page.html_content)\n                    case \"html\":\n                        yield page.html_content\n                    case \"text\":\n                        txt_content = page.get_all_text(\n                            strip=True, ignore_tags=(\"script\", \"style\", \"noscript\", \"svg\", \"iframe\")","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/D4Vinci/Scrapling/blob/5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f/scrapling/core/shell.py#L608-L644","documentation":"Convertor._extract_content is the extraction pipeline for markdown/html/text output. Its first guard requires the page argument to be a truthy Selector instance; anything else (str, bytes, Response, None) raises TypeError immediately. Note the falsy check: an empty/None page also fails even before the isinstance check matters.","triggerScenarios":"Calling Convertor methods with a Response object instead of its .selector, passing page.html_content (a string), or calling the private _extract_content directly on raw content. Marked pragma: no cover because public entry points normally always pass a Selector.","commonSituations":"Users reaching into the private API, or older snippets where a function took html text and now expects a Selector after a version refactor.","solutions":["Fetch first so you hold a Selector: `page = Fetcher.get(url)` then pass `page` (Selector), not `page.content`","If you have raw HTML, wrap it: `Selector(content=html_string)` before extraction","Use public APIs (fetch/shell commands or write_content_to_file) instead of _extract_content"],"exampleFix":"# before\ncontent = Convertor._extract_content(response, 'markdown')\n\n# after\ncontent = Convertor._extract_content(response.selector, 'markdown')","handlingStrategy":"type-guard","validationCode":"from scrapling.parser import Selector\n\nassert isinstance(page, Selector) and bool(page), 'pass a non-empty Selector, not raw content or a Response'","typeGuard":"from scrapling.parser import Selector\nfrom typing import Any\n\ndef is_selector(value: Any) -> bool:\n    return isinstance(value, Selector) and bool(value)","tryCatchPattern":null,"preventionTips":["Use public entry points (CLI, write_content_to_file) instead of _extract_content","Always fetch to a Selector and pass that object; never .content/.html_content"],"tags":["shell","internal-api","typeerror","type-guard"],"backgroundTag":null,"analyzedSha":"5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f","analyzedAt":"2026-08-14T22:23:09.440Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}