Python API¶
The public Python API currently lives under scrape_smith.tools.
Table helpers¶
Extract tabular data from HTML documents.
- class scrape_smith.tools.tables.HtmlTable(caption: str | None, headers: list[str], rows: list[list[str]])[source]¶
Bases:
objectA table extracted from an HTML document.
- caption: str | None¶
- headers: list[str]¶
- rows: list[list[str]]¶
- scrape_smith.tools.tables.extract_tables(target: str | Path) list[HtmlTable][source]¶
Extract tables from a local HTML file path or HTTP(S) URL.
List helpers¶
Extract list data from HTML documents.
- class scrape_smith.tools.lists.HtmlDefinitionList(items: list[dict[str, str]])[source]¶
Bases:
objectA definition list extracted from an HTML document.
- items: list[dict[str, str]]¶
- class scrape_smith.tools.lists.HtmlList(tag: str, items: list[str])[source]¶
Bases:
objectAn ordered or unordered list extracted from an HTML document.
- items: list[str]¶
- tag: str¶
- scrape_smith.tools.lists.extract_lists(target: str | Path) list[HtmlList | HtmlDefinitionList][source]¶
Extract lists from a local HTML file path or HTTP(S) URL.
- scrape_smith.tools.lists.extract_lists_from_html(html: str) list[HtmlList | HtmlDefinitionList][source]¶
Extract lists from an HTML string.
Content helpers¶
Extract body content from HTML documents as JSONL-ready records.
- scrape_smith.tools.content.extract_content_records(target: str | Path) list[dict[str, str]][source]¶
Extract body text records from a local HTML file path or HTTP(S) URL.
Extract helpers (three-in-one)¶
Extract all content, tables, and lists from an HTML document as JSONL records.
- scrape_smith.tools.extract.extract_all(target: str | Path) list[dict[str, str]][source]¶
Extract all records from a local HTML file path or HTTP(S) URL.
Download helpers¶
Download file URLs into a local directory.
- class scrape_smith.tools.downloads.DownloadResult(url: str, status: str, path: Path | None = None, reason: str | None = None)[source]¶
Bases:
objectResult for one URL from a download run.
- path: Path | None = None¶
- reason: str | None = None¶
- status: str¶
- url: str¶
- class scrape_smith.tools.downloads.DownloadSummary(output_dir: Path, results: list[DownloadResult])[source]¶
Bases:
objectSummary for a file download run.
- property downloaded_count: int¶
- property failed_count: int¶
- output_dir: Path¶
- results: list[DownloadResult]¶
- property skipped_count: int¶
- scrape_smith.tools.downloads.available_directory(path: Path) Path[source]¶
Return
pathor a suffixed sibling that does not exist.
- scrape_smith.tools.downloads.available_path(path: Path) Path[source]¶
Return
pathor a suffixed sibling that does not exist.
- scrape_smith.tools.downloads.content_type_extension(content_type: str | None) str | None[source]¶
Return a supported target extension for a Content-Type value.
- scrape_smith.tools.downloads.default_download_dir(url_list_path: str | Path) Path[source]¶
Return a collision-safe output directory for a URL list file.
- scrape_smith.tools.downloads.download_files(url_list_path: str | Path, output_dir: str | Path | None = None, *, delay_seconds: float = 1.0, timeout_seconds: int = 30, reporter: Callable[[str], None] | None = None) DownloadSummary[source]¶
Download target file URLs listed in a text file.
Blank lines and lines starting with
#are ignored. Downloads run sequentially with a delay between requests by default.
- scrape_smith.tools.downloads.download_url(url: str, output_dir: str | Path, *, timeout_seconds: int = 30) DownloadResult[source]¶
Download one URL when it resolves to a supported target file.
- scrape_smith.tools.downloads.fallback_filename(extension: str) str[source]¶
Return an epoch-based fallback filename with fixed-width milliseconds.
- scrape_smith.tools.downloads.read_url_list(url_list_path: str | Path) list[str][source]¶
Read non-empty, non-comment URL lines from a text file.
- scrape_smith.tools.downloads.response_filename(content_disposition: str | None) str | None[source]¶
Extract a filename from a Content-Disposition header.
- scrape_smith.tools.downloads.safe_filename(filename: str) str[source]¶
Return a filesystem-safe basename preserving the original extension.
CLI helpers¶
The CLI module is importable for tests and advanced integrations, but most
callers should use the scrape command directly.
Command line interface for scrape-smith.
- scrape_smith.cli.write_lists(lists: list[HtmlList | HtmlDefinitionList], output_format: str, output_file: TextIO) None[source]¶