html-reader-llm 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ClericPy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.4
2
+ Name: html-reader-llm
3
+ Version: 0.0.1
4
+ Summary: HTML simplification and intelligent extraction for LLM
5
+ Author-email: Clericpy <clericpy@gmail.com>
6
+ Requires-Python: >=3.12
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: minify-html>=0.18.1
10
+ Requires-Dist: python-dotenv>=1.2.2
11
+ Requires-Dist: selectolax>=0.4.7
12
+ Requires-Dist: trafilatura>=2.2.0
13
+
14
+ # html-reader-llm
15
+
16
+ HTML simplification and intelligent extraction for LLM.
17
+
18
+ ## Features
19
+
20
+ - HTML simplification for LLM consumption
21
+ - Render detection (HTTP vs Chrome)
22
+ - LLM-powered page classification and CSS selector generation
23
+ - CSS selector validation
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pip install html-reader-llm
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```bash
34
+ # Simplify HTML
35
+ html-reader-llm simplify < page.html
36
+
37
+ # Detect if browser rendering is needed
38
+ html-reader-llm detect https://example.com
39
+
40
+ # Full analysis with LLM
41
+ html-reader-llm analyze https://example.com
42
+
43
+ # Fetch HTML
44
+ html-reader-llm fetch https://example.com
45
+
46
+ # Validate CSS selectors
47
+ html-reader-llm validate https://example.com --rules-file selectors.json
48
+ ```
49
+
50
+ ## License
51
+
52
+ MIT
@@ -0,0 +1,39 @@
1
+ # html-reader-llm
2
+
3
+ HTML simplification and intelligent extraction for LLM.
4
+
5
+ ## Features
6
+
7
+ - HTML simplification for LLM consumption
8
+ - Render detection (HTTP vs Chrome)
9
+ - LLM-powered page classification and CSS selector generation
10
+ - CSS selector validation
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pip install html-reader-llm
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ # Simplify HTML
22
+ html-reader-llm simplify < page.html
23
+
24
+ # Detect if browser rendering is needed
25
+ html-reader-llm detect https://example.com
26
+
27
+ # Full analysis with LLM
28
+ html-reader-llm analyze https://example.com
29
+
30
+ # Fetch HTML
31
+ html-reader-llm fetch https://example.com
32
+
33
+ # Validate CSS selectors
34
+ html-reader-llm validate https://example.com --rules-file selectors.json
35
+ ```
36
+
37
+ ## License
38
+
39
+ MIT
@@ -0,0 +1,28 @@
1
+ [project]
2
+ name = "html-reader-llm"
3
+ version = "0.0.1"
4
+ description = "HTML simplification and intelligent extraction for LLM"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Clericpy", email = "clericpy@gmail.com" }
8
+ ]
9
+ requires-python = ">=3.12"
10
+ dependencies = [
11
+ "minify-html>=0.18.1",
12
+ "python-dotenv>=1.2.2",
13
+ "selectolax>=0.4.7",
14
+ "trafilatura>=2.2.0",
15
+ ]
16
+
17
+
18
+ [project.scripts]
19
+ html-reader-llm = "html_reader_llm.cli:main"
20
+
21
+ [build-system]
22
+ requires = ["flit_core>=3.12,<4"]
23
+ build-backend = "flit_core.buildapi"
24
+
25
+ [dependency-groups]
26
+ dev = [
27
+ "pytest>=9.1.1",
28
+ ]
@@ -0,0 +1,39 @@
1
+ """html-reader-llm — HTML simplification and intelligent extraction for LLM.
2
+
3
+ Quick start (pip install):
4
+ pip install selectolax
5
+ from html_reader_llm import simplify_html
6
+ result = simplify_html(html_string)
7
+
8
+ Copy usage (no pip):
9
+ Copy settings.py and simplify.py into your project,
10
+ change `from html_reader_llm import settings` to `from . import settings` (or
11
+ adjust the import path), then use:
12
+ from simplify import simplify_html
13
+ result = simplify_html(html_string)
14
+ """
15
+
16
+ from html_reader_llm.browser import (
17
+ BrowserNotFoundError,
18
+ detect_browser_paths,
19
+ get_browser_path,
20
+ validate_browser_path,
21
+ )
22
+ from html_reader_llm.llm import AnalysisResult, analyze_page
23
+ from html_reader_llm.render_detect import RenderDetectResult, detect_render
24
+ from html_reader_llm.selector_validator import SelectorValidator, validate_url_selectors
25
+ from html_reader_llm.simplify import simplify_html
26
+
27
+ __all__ = [
28
+ "AnalysisResult",
29
+ "BrowserNotFoundError",
30
+ "RenderDetectResult",
31
+ "SelectorValidator",
32
+ "analyze_page",
33
+ "detect_browser_paths",
34
+ "detect_render",
35
+ "get_browser_path",
36
+ "simplify_html",
37
+ "validate_browser_path",
38
+ "validate_url_selectors",
39
+ ]
@@ -0,0 +1,161 @@
1
+ """Chrome/Edge browser path detection — platform-aware discovery and validation.
2
+
3
+ Three usage modes:
4
+ - detect_browser_paths() → list all found paths
5
+ - get_browser_path() → auto-select first (or None), checks ENV first
6
+ - validate_browser_path(path) → validate user path, raise if invalid
7
+
8
+ ENV override: HTMLREADER_CHROME_PATH
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import logging
14
+ import os
15
+ import platform
16
+ import shutil
17
+ import subprocess
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+ # --- Platform-specific known paths ---
22
+
23
+ WIN32_PATHS: list[str] = [
24
+ "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
25
+ "C:/Program Files/Google/Chrome/Application/chrome.exe",
26
+ "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
27
+ "C:/Program Files/Microsoft/Edge/Application/msedge.exe",
28
+ ]
29
+
30
+ # Add %USERPROFILE% based paths at runtime
31
+ _WIN32_USERPROFILE_PATHS: list[str] = [
32
+ "AppData/Local/Google/Chrome/Application/chrome.exe",
33
+ "AppData/Local/Microsoft/Edge/Application/msedge.exe",
34
+ ]
35
+
36
+ LINUX_PATHS: list[str] = [
37
+ "google-chrome",
38
+ "google-chrome-stable",
39
+ "google-chrome-beta",
40
+ "google-chrome-dev",
41
+ "microsoft-edge-stable",
42
+ ]
43
+
44
+ DARWIN_PATHS: list[str] = [
45
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
46
+ "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
47
+ ]
48
+
49
+ _VERSION_PREFIXES = (b"Google Chrome ", b"Microsoft Edge")
50
+
51
+
52
+ class BrowserNotFoundError(Exception):
53
+ """Raised when no valid Chrome/Edge executable is found."""
54
+
55
+
56
+ def _iter_browser_paths() -> list[str]:
57
+ """Detect installed Chrome/Edge paths on the current platform.
58
+
59
+ Returns a list of absolute paths, sorted by mtime descending (newest first).
60
+ """
61
+ current = platform.system()
62
+ found: set[str] = set()
63
+
64
+ if current == "Windows":
65
+ # Fixed known paths
66
+ for p in WIN32_PATHS:
67
+ if os.path.isfile(p):
68
+ found.add(os.path.abspath(p))
69
+ # USERPROFILE-based paths
70
+ userprofile = os.environ.get("USERPROFILE", "")
71
+ if userprofile:
72
+ for rel in _WIN32_USERPROFILE_PATHS:
73
+ full = os.path.join(userprofile, rel)
74
+ if os.path.isfile(full):
75
+ found.add(os.path.abspath(full))
76
+
77
+ elif current == "Linux":
78
+ for cmd in LINUX_PATHS:
79
+ resolved = shutil.which(cmd)
80
+ if resolved and _verify_browser(resolved):
81
+ found.add(os.path.abspath(resolved))
82
+
83
+ elif current == "Darwin":
84
+ for p in DARWIN_PATHS:
85
+ if os.path.isfile(p):
86
+ found.add(os.path.abspath(p))
87
+
88
+ else:
89
+ logger.warning("Unsupported platform: %s", current)
90
+
91
+ result = sorted(found, key=_mtime_key, reverse=True)
92
+ return result
93
+
94
+
95
+ def _verify_browser(path: str) -> bool:
96
+ """Check if a binary is actually Chrome/Edge by running --version."""
97
+ try:
98
+ out = subprocess.check_output(
99
+ [path, "--version"], timeout=2, stderr=subprocess.DEVNULL
100
+ )
101
+ return any(out.startswith(prefix) for prefix in _VERSION_PREFIXES)
102
+ except (FileNotFoundError, subprocess.TimeoutExpired, OSError):
103
+ return False
104
+
105
+
106
+ def _mtime_key(path: str) -> float:
107
+ """Get mtime for sorting, 0 if file doesn't exist."""
108
+ try:
109
+ return os.path.getmtime(path)
110
+ except OSError:
111
+ return 0.0
112
+
113
+
114
+ def detect_browser_paths() -> list[str]:
115
+ """List all detected Chrome/Edge browser paths on this platform.
116
+
117
+ Returns absolute paths sorted by modification time (newest first).
118
+ """
119
+ return _iter_browser_paths()
120
+
121
+
122
+ def get_browser_path() -> str | None:
123
+ """Auto-select the best browser path.
124
+
125
+ Priority:
126
+ 1. HTMLREADER_CHROME_PATH env var (if set and valid)
127
+ 2. First detected path (newest by mtime)
128
+
129
+ Returns None if no browser is found.
130
+ """
131
+ # ENV override
132
+ env_path = os.environ.get("HTMLREADER_CHROME_PATH", "").strip()
133
+ if env_path:
134
+ try:
135
+ return validate_browser_path(env_path)
136
+ except BrowserNotFoundError:
137
+ logger.warning(
138
+ "HTMLREADER_CHROME_PATH=%s is invalid, falling back to auto-detect",
139
+ env_path,
140
+ )
141
+
142
+ paths = detect_browser_paths()
143
+ return paths[0] if paths else None
144
+
145
+
146
+ def validate_browser_path(path: str) -> str:
147
+ """Validate a user-provided browser path.
148
+
149
+ Args:
150
+ path: Path to Chrome/Edge executable.
151
+
152
+ Returns:
153
+ Absolute resolved path.
154
+
155
+ Raises:
156
+ BrowserNotFoundError: If the path does not exist or is not a valid file.
157
+ """
158
+ resolved = os.path.abspath(path)
159
+ if not os.path.isfile(resolved):
160
+ raise BrowserNotFoundError(f"Browser executable not found: {resolved}")
161
+ return resolved