snaprender 0.2.4__tar.gz → 0.3.0__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.
- {snaprender-0.2.4 → snaprender-0.3.0}/PKG-INFO +1 -1
- {snaprender-0.2.4 → snaprender-0.3.0}/pyproject.toml +1 -1
- {snaprender-0.2.4 → snaprender-0.3.0}/snaprender/__init__.py +1 -1
- {snaprender-0.2.4 → snaprender-0.3.0}/snaprender/client.py +88 -35
- {snaprender-0.2.4 → snaprender-0.3.0}/.gitignore +0 -0
- {snaprender-0.2.4 → snaprender-0.3.0}/LICENSE +0 -0
- {snaprender-0.2.4 → snaprender-0.3.0}/README.md +0 -0
|
@@ -44,8 +44,10 @@ class SnapRender:
|
|
|
44
44
|
|
|
45
45
|
def capture(
|
|
46
46
|
self,
|
|
47
|
-
url: str,
|
|
47
|
+
url: Optional[str] = None,
|
|
48
48
|
*,
|
|
49
|
+
html: Optional[str] = None,
|
|
50
|
+
markdown: Optional[str] = None,
|
|
49
51
|
format: str = "png",
|
|
50
52
|
width: Optional[int] = None,
|
|
51
53
|
height: Optional[int] = None,
|
|
@@ -63,40 +65,91 @@ class SnapRender:
|
|
|
63
65
|
cache_ttl: Optional[int] = None,
|
|
64
66
|
response_type: Optional[str] = None,
|
|
65
67
|
) -> "bytes | dict[str, Any]":
|
|
66
|
-
"""Capture a screenshot.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
68
|
+
"""Capture a screenshot. Provide exactly one of: url, html, or markdown.
|
|
69
|
+
|
|
70
|
+
When html or markdown is provided, uses POST with JSON body.
|
|
71
|
+
When url is provided, uses GET with query parameters (backward compatible).
|
|
72
|
+
Returns bytes by default, or a dict when response_type='json'.
|
|
73
|
+
"""
|
|
74
|
+
use_post = bool(html or markdown)
|
|
75
|
+
|
|
76
|
+
if use_post:
|
|
77
|
+
body: dict[str, Any] = {"format": format}
|
|
78
|
+
if url is not None:
|
|
79
|
+
body["url"] = url
|
|
80
|
+
if html is not None:
|
|
81
|
+
body["html"] = html
|
|
82
|
+
if markdown is not None:
|
|
83
|
+
body["markdown"] = markdown
|
|
84
|
+
if width is not None:
|
|
85
|
+
body["width"] = width
|
|
86
|
+
if height is not None:
|
|
87
|
+
body["height"] = height
|
|
88
|
+
if full_page is not None:
|
|
89
|
+
body["full_page"] = full_page
|
|
90
|
+
if quality is not None:
|
|
91
|
+
body["quality"] = quality
|
|
92
|
+
if delay is not None:
|
|
93
|
+
body["delay"] = delay
|
|
94
|
+
if dark_mode is not None:
|
|
95
|
+
body["dark_mode"] = dark_mode
|
|
96
|
+
if block_ads is not None:
|
|
97
|
+
body["block_ads"] = block_ads
|
|
98
|
+
if block_cookie_banners is not None:
|
|
99
|
+
body["block_cookie_banners"] = block_cookie_banners
|
|
100
|
+
if hide_selectors is not None:
|
|
101
|
+
body["hide_selectors"] = hide_selectors
|
|
102
|
+
if click_selector is not None:
|
|
103
|
+
body["click_selector"] = click_selector
|
|
104
|
+
if device is not None:
|
|
105
|
+
body["device"] = device
|
|
106
|
+
if user_agent is not None:
|
|
107
|
+
body["user_agent"] = user_agent
|
|
108
|
+
if cache is not None:
|
|
109
|
+
body["cache"] = cache
|
|
110
|
+
if cache_ttl is not None:
|
|
111
|
+
body["cache_ttl"] = cache_ttl
|
|
112
|
+
if response_type is not None:
|
|
113
|
+
body["response_type"] = response_type
|
|
114
|
+
|
|
115
|
+
resp = self._client.post("/v1/screenshot", json=body)
|
|
116
|
+
else:
|
|
117
|
+
if not url:
|
|
118
|
+
raise ValueError("One of url, html, or markdown is required")
|
|
119
|
+
params: dict[str, Any] = {"url": url, "format": format}
|
|
120
|
+
if width is not None:
|
|
121
|
+
params["width"] = width
|
|
122
|
+
if height is not None:
|
|
123
|
+
params["height"] = height
|
|
124
|
+
if full_page is not None:
|
|
125
|
+
params["full_page"] = str(full_page).lower()
|
|
126
|
+
if quality is not None:
|
|
127
|
+
params["quality"] = quality
|
|
128
|
+
if delay is not None:
|
|
129
|
+
params["delay"] = delay
|
|
130
|
+
if dark_mode is not None:
|
|
131
|
+
params["dark_mode"] = str(dark_mode).lower()
|
|
132
|
+
if block_ads is not None:
|
|
133
|
+
params["block_ads"] = str(block_ads).lower()
|
|
134
|
+
if block_cookie_banners is not None:
|
|
135
|
+
params["block_cookie_banners"] = str(block_cookie_banners).lower()
|
|
136
|
+
if hide_selectors is not None:
|
|
137
|
+
params["hide_selectors"] = hide_selectors
|
|
138
|
+
if click_selector is not None:
|
|
139
|
+
params["click_selector"] = click_selector
|
|
140
|
+
if device is not None:
|
|
141
|
+
params["device"] = device
|
|
142
|
+
if user_agent is not None:
|
|
143
|
+
params["user_agent"] = user_agent
|
|
144
|
+
if cache is not None:
|
|
145
|
+
params["cache"] = str(cache).lower()
|
|
146
|
+
if cache_ttl is not None:
|
|
147
|
+
params["cache_ttl"] = cache_ttl
|
|
148
|
+
if response_type is not None:
|
|
149
|
+
params["response_type"] = response_type
|
|
150
|
+
|
|
151
|
+
resp = self._client.get("/v1/screenshot", params=params)
|
|
152
|
+
|
|
100
153
|
if resp.status_code != 200:
|
|
101
154
|
self._raise_error(resp)
|
|
102
155
|
if response_type == "json":
|
|
File without changes
|
|
File without changes
|
|
File without changes
|