-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.ts
More file actions
306 lines (261 loc) · 7.59 KB
/
web.ts
File metadata and controls
306 lines (261 loc) · 7.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../core/resource';
import { APIPromise } from '../core/api-promise';
import { RequestOptions } from '../internal/request-options';
export class Web extends APIResource {
/**
* Capture a screenshot of a website. Supports both viewport (standard browser
* view) and full-page screenshots. Can also screenshot specific page types (login,
* pricing, etc.) by using heuristics to find the appropriate URL. Returns a URL to
* the uploaded screenshot image hosted on our CDN.
*/
screenshot(query: WebScreenshotParams, options?: RequestOptions): APIPromise<WebScreenshotResponse> {
return this._client.get('/brand/screenshot', { query, ...options });
}
/**
* Scrapes the given URL and returns the raw HTML content of the page.
*/
webScrapeHTML(
query: WebWebScrapeHTMLParams,
options?: RequestOptions,
): APIPromise<WebWebScrapeHTMLResponse> {
return this._client.get('/web/scrape/html', { query, ...options });
}
/**
* Scrapes all images from the given URL. Extracts images from img, svg,
* picture/source, link, and video elements including inline SVGs, base64 data
* URIs, and standard URLs.
*/
webScrapeImages(
query: WebWebScrapeImagesParams,
options?: RequestOptions,
): APIPromise<WebWebScrapeImagesResponse> {
return this._client.get('/web/scrape/images', { query, ...options });
}
/**
* Scrapes the given URL, converts the HTML content to Markdown, and returns the
* result.
*/
webScrapeMd(query: WebWebScrapeMdParams, options?: RequestOptions): APIPromise<WebWebScrapeMdResponse> {
return this._client.get('/web/scrape/markdown', { query, ...options });
}
/**
* Crawls the sitemap of the given domain and returns all discovered page URLs.
* Supports sitemap index files (recursive), parallel fetching with concurrency
* control, deduplication, and filters out non-page resources (images, PDFs, etc.).
*/
webScrapeSitemap(
query: WebWebScrapeSitemapParams,
options?: RequestOptions,
): APIPromise<WebWebScrapeSitemapResponse> {
return this._client.get('/web/scrape/sitemap', { query, ...options });
}
}
export interface WebScreenshotResponse {
/**
* HTTP status code
*/
code?: number;
/**
* The normalized domain that was processed
*/
domain?: string;
/**
* Public URL of the uploaded screenshot image
*/
screenshot?: string;
/**
* Type of screenshot that was captured
*/
screenshotType?: 'viewport' | 'fullPage';
/**
* Status of the response, e.g., 'ok'
*/
status?: string;
}
export interface WebWebScrapeHTMLResponse {
/**
* Raw HTML content of the page
*/
html: string;
/**
* Indicates success
*/
success: true;
/**
* The URL that was scraped
*/
url: string;
}
export interface WebWebScrapeImagesResponse {
/**
* Array of scraped images
*/
images: Array<WebWebScrapeImagesResponse.Image>;
/**
* Indicates success
*/
success: true;
/**
* The URL that was scraped
*/
url: string;
}
export namespace WebWebScrapeImagesResponse {
export interface Image {
/**
* Alt text of the image, or null if not present
*/
alt: string | null;
/**
* The HTML element the image was found in
*/
element: 'img' | 'svg' | 'link' | 'source' | 'video';
/**
* The image source - can be a URL, inline HTML (for SVGs), or a base64 data URI
*/
src: string;
/**
* The type/format of the src value
*/
type: 'url' | 'html' | 'base64';
}
}
export interface WebWebScrapeMdResponse {
/**
* Page content converted to GitHub Flavored Markdown
*/
markdown: string;
/**
* Indicates success
*/
success: true;
/**
* The URL that was scraped
*/
url: string;
}
export interface WebWebScrapeSitemapResponse {
/**
* The normalized domain that was crawled
*/
domain: string;
/**
* Metadata about the sitemap crawl operation
*/
meta: WebWebScrapeSitemapResponse.Meta;
/**
* Indicates success
*/
success: true;
/**
* Array of discovered page URLs from the sitemap (max 500)
*/
urls: Array<string>;
}
export namespace WebWebScrapeSitemapResponse {
/**
* Metadata about the sitemap crawl operation
*/
export interface Meta {
/**
* Number of errors encountered during crawling
*/
errors: number;
/**
* Total number of sitemap files discovered
*/
sitemapsDiscovered: number;
/**
* Number of sitemap files successfully fetched and parsed
*/
sitemapsFetched: number;
/**
* Number of sitemap files skipped (due to errors, timeouts, or limits)
*/
sitemapsSkipped: number;
}
}
export interface WebScreenshotParams {
/**
* Domain name to take screenshot of (e.g., 'example.com', 'google.com'). The
* domain will be automatically normalized and validated.
*/
domain: string;
/**
* Optional parameter to determine screenshot type. If 'true', takes a full page
* screenshot capturing all content. If 'false' or not provided, takes a viewport
* screenshot (standard browser view).
*/
fullScreenshot?: 'true' | 'false';
/**
* Optional parameter to specify which page type to screenshot. If provided, the
* system will scrape the domain's links and use heuristics to find the most
* appropriate URL for the specified page type (30 supported languages). If not
* provided, screenshots the main domain landing page.
*/
page?: 'login' | 'signup' | 'blog' | 'careers' | 'pricing' | 'terms' | 'privacy' | 'contact';
/**
* Optional parameter to prioritize screenshot capture. If 'speed', optimizes for
* faster capture with basic quality. If 'quality', optimizes for higher quality
* with longer wait times. Defaults to 'quality' if not provided.
*/
prioritize?: 'speed' | 'quality';
}
export interface WebWebScrapeHTMLParams {
/**
* Full URL to scrape (must include http:// or https:// protocol)
*/
url: string;
}
export interface WebWebScrapeImagesParams {
/**
* Full URL to scrape images from (must include http:// or https:// protocol)
*/
url: string;
}
export interface WebWebScrapeMdParams {
/**
* Full URL to scrape and convert to markdown (must include http:// or https://
* protocol)
*/
url: string;
/**
* Include image references in Markdown output
*/
includeImages?: boolean;
/**
* Preserve hyperlinks in Markdown output
*/
includeLinks?: boolean;
/**
* Shorten base64-encoded image data in the Markdown output
*/
shortenBase64Images?: boolean;
}
export interface WebWebScrapeSitemapParams {
/**
* Domain name to crawl sitemaps for (e.g., 'example.com'). The domain will be
* automatically normalized and validated.
*/
domain: string;
/**
* Maximum number of links to return from the sitemap crawl. Defaults to 10,000.
* Minimum is 1, maximum is 100,000.
*/
maxLinks?: number;
}
export declare namespace Web {
export {
type WebScreenshotResponse as WebScreenshotResponse,
type WebWebScrapeHTMLResponse as WebWebScrapeHTMLResponse,
type WebWebScrapeImagesResponse as WebWebScrapeImagesResponse,
type WebWebScrapeMdResponse as WebWebScrapeMdResponse,
type WebWebScrapeSitemapResponse as WebWebScrapeSitemapResponse,
type WebScreenshotParams as WebScreenshotParams,
type WebWebScrapeHTMLParams as WebWebScrapeHTMLParams,
type WebWebScrapeImagesParams as WebWebScrapeImagesParams,
type WebWebScrapeMdParams as WebWebScrapeMdParams,
type WebWebScrapeSitemapParams as WebWebScrapeSitemapParams,
};
}