@scrapa/sdk 0.2.2 → 0.4.0
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.
- package/README.md +47 -17
- package/dist/client.js +2 -2
- package/dist/client.js.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/generated/contract.d.ts +66 -10
- package/dist/generated/contract.d.ts.map +1 -1
- package/dist/generated/contract.js +24 -9
- package/dist/generated/contract.js.map +1 -1
- package/dist/generated/operations.d.ts +77 -45
- package/dist/generated/operations.d.ts.map +1 -1
- package/dist/generated/operations.js +89 -43
- package/dist/generated/operations.js.map +1 -1
- package/dist/generated/params.d.ts +250 -98
- package/dist/generated/params.d.ts.map +1 -1
- package/dist/generated/retry.d.ts +2 -2
- package/dist/generated/retry.js +3 -3
- package/dist/generated/transport.js +2 -2
- package/package.json +2 -2
- package/src/client.ts +2 -2
- package/src/errors.ts +1 -1
- package/src/generated/contract.ts +81 -9
- package/src/generated/operations.ts +109 -43
- package/src/generated/params.ts +252 -98
- package/src/generated/retry.ts +3 -3
- package/src/generated/transport.ts +2 -2
package/src/generated/params.ts
CHANGED
|
@@ -6,36 +6,64 @@
|
|
|
6
6
|
|
|
7
7
|
/** Arguments for `scrape()`. */
|
|
8
8
|
export interface ScrapeParams {
|
|
9
|
-
/** The page to read. An http(s) URL
|
|
9
|
+
/** The page to read. An http(s) URL. Private and loopback hosts are refused. */
|
|
10
10
|
url: string;
|
|
11
11
|
/** How to read it. "fetch" is a plain HTTP request; "browser" renders the page in a real
|
|
12
|
-
* Chromium; "auto" fetches first and escalates to the browser when the body
|
|
13
|
-
* JavaScript shell, billing whichever engine answered.
|
|
12
|
+
* Chromium; "auto" (the default) fetches first and escalates to the browser when the body
|
|
13
|
+
* turns out to be a JavaScript shell, billing whichever engine answered. A POST and "raw"
|
|
14
|
+
* always use "fetch", so leave it out for them. */
|
|
14
15
|
engine?: "auto" | "fetch" | "browser";
|
|
15
|
-
/** Whether to try again a different way when the first attempt is blocked.
|
|
16
|
-
* one try
|
|
17
|
-
* call: with `auto`, trying again is what charges the browser price instead of
|
|
16
|
+
/** Whether to try again a different way when the first attempt is blocked. On by default.
|
|
17
|
+
* `false` stops after one try. The site's refusal is your answer, and it costs nothing. It is
|
|
18
|
+
* how you bound a call: with `auto`, trying again is what charges the browser price instead of
|
|
19
|
+
* the fetch one. A POST is sent once, so it is off for a POST. */
|
|
18
20
|
escalate?: boolean;
|
|
21
|
+
/** The HTTP method. "POST" sends `body` to the URL, for a search form or a JSON query. It is
|
|
22
|
+
* sent once: never retried and never sent again another way, because sending it twice could
|
|
23
|
+
* repeat what it did. */
|
|
24
|
+
method?: "GET" | "POST";
|
|
25
|
+
/** What a POST sends, at most 64 KB. Set its type in `headers`: `{"content-type":
|
|
26
|
+
* "application/json"}` for JSON, or `application/x-www-form-urlencoded` for a form. If the
|
|
27
|
+
* site redirects, a 301, 302 or 303 reads the next page with GET and without the body; a 307
|
|
28
|
+
* or 308 sends it again only if the protocol, host and port stay the same, and otherwise stops
|
|
29
|
+
* and names the new address. */
|
|
30
|
+
body?: string;
|
|
19
31
|
/** How many extra tries to give a page the site blocks, each from a different address. 0 (the
|
|
20
32
|
* default) takes the site's first no as the answer. A blocked page costs nothing, so a try
|
|
21
|
-
* that is blocked again is free
|
|
33
|
+
* that is blocked again is free, but it takes as long as the first one did, so the call can
|
|
22
34
|
* run that many times longer. */
|
|
23
35
|
retry?: number;
|
|
24
36
|
/** What to hand back. "screenshot" and "pdf" come back as base64 and need the browser engine;
|
|
25
37
|
* asking for both costs no more than one. "extract" is the page read into fields by a model,
|
|
26
|
-
* and needs an `extract` block saying which ones.
|
|
27
|
-
|
|
38
|
+
* and needs an `extract` block saying which ones. A link to a PDF or a Word (.docx) file is
|
|
39
|
+
* read into text, so the text formats work on it too. We read files up to 25 MB and the first
|
|
40
|
+
* 200 pages, at the fetch price. "raw" is the file exactly as the site sent it, as base64 with
|
|
41
|
+
* its content type: a PDF report, an image, a spreadsheet. It uses the fetch engine and holds
|
|
42
|
+
* up to 5 MB; a larger file answers FILE_TOO_LARGE at no charge, never cut short. */
|
|
43
|
+
formats?: ("markdown" | "html" | "text" | "links" | "screenshot" | "pdf" | "extract" | "raw")[];
|
|
44
|
+
/** Read only the page's main content into `markdown`, `text` and `extract`: the article or the
|
|
45
|
+
* product, without the menus, ads and related links around it. On by default. Set `false` for
|
|
46
|
+
* the whole page. When the main content is under 50 words, you get the whole page instead.
|
|
47
|
+
* `html` and `links` always hold the whole page. */
|
|
48
|
+
onlyMainContent?: boolean;
|
|
49
|
+
/** CSS selectors for the parts of the page to keep, such as `["h1", ".price"]`. `markdown`,
|
|
50
|
+
* `text` and `extract` then hold only what they match, in page order, and `onlyMainContent` no
|
|
51
|
+
* longer applies. Hidden parts are never kept. Up to 20 selectors, 256 characters each. */
|
|
52
|
+
includeTags?: string[];
|
|
53
|
+
/** CSS selectors for the parts of the page to leave out of `markdown`, `text` and `extract`,
|
|
54
|
+
* such as `[".comments", "#newsletter"]`. Up to 20 selectors, 256 characters each. */
|
|
55
|
+
excludeTags?: string[];
|
|
28
56
|
/** What the page should answer with. Set `"json"` when you are reading an API: anything else
|
|
29
|
-
* that comes back
|
|
30
|
-
*
|
|
31
|
-
*
|
|
57
|
+
* that comes back (a maintenance notice, a "checking your browser" page, a login form) is then
|
|
58
|
+
* not your answer. It costs nothing, and we try again from another address instead of handing
|
|
59
|
+
* you a page you cannot parse. Without it, whatever the page returns is your answer. */
|
|
32
60
|
expect?: "json";
|
|
33
61
|
/** What to pull out of the page, for the "extract" format. A model reads the page and fills in
|
|
34
|
-
* the shape you asked for
|
|
62
|
+
* the shape you asked for. Give it a JSON Schema, a sentence, or both. It reads what the page
|
|
35
63
|
* says; it does not do arithmetic over it, so ask for the numbers and add them up in your own
|
|
36
64
|
* code. */
|
|
37
65
|
extract?: {
|
|
38
|
-
/** The shape you want back, as JSON Schema
|
|
66
|
+
/** The shape you want back, as JSON Schema: an object whose properties are the fields you
|
|
39
67
|
* need. A field the page does not mention comes back null; nothing is invented to fill it. */
|
|
40
68
|
schema?: Record<string, unknown>;
|
|
41
69
|
/** What to pull out, in your own words: `the price, the author and the date it was
|
|
@@ -46,7 +74,7 @@ export interface ScrapeParams {
|
|
|
46
74
|
/** Where the request leaves from. Defaults to the managed residential pool. */
|
|
47
75
|
proxy?: {
|
|
48
76
|
/** Which exit to leave through. "residential" is the managed pool, metered by the megabyte;
|
|
49
|
-
* "custom" is your own proxy
|
|
77
|
+
* "custom" is your own proxy, free on every plan, bytes never billed. */
|
|
50
78
|
pool?: "residential" | "custom";
|
|
51
79
|
/** Your own proxy, `http(s)://[user:pass@]host:port`. Required for pool "custom", refused
|
|
52
80
|
* for the managed one. */
|
|
@@ -66,7 +94,7 @@ export interface ScrapeParams {
|
|
|
66
94
|
* charge; ask for the state or the country alone. */
|
|
67
95
|
city?: string;
|
|
68
96
|
};
|
|
69
|
-
/** How to render it. Only the browser engine reads these
|
|
97
|
+
/** How to render it. Only the browser engine reads these. With `auto` they apply if the page
|
|
70
98
|
* turns out to need one. */
|
|
71
99
|
browser?: {
|
|
72
100
|
/** When the page counts as loaded. "load" (the default) waits for images and stylesheets;
|
|
@@ -74,9 +102,9 @@ export interface ScrapeParams {
|
|
|
74
102
|
* page stops asking for things. Every page gets a short settle after this whichever you
|
|
75
103
|
* pick. */
|
|
76
104
|
waitUntil?: "load" | "domcontentloaded" | "networkidle";
|
|
77
|
-
/** Wait until this CSS selector is on the page
|
|
78
|
-
* script draws. If it never shows up the call comes back as a timeout at no charge,
|
|
79
|
-
* than the half-built page. */
|
|
105
|
+
/** Wait until this CSS selector is on the page. It is the dependable way to read something
|
|
106
|
+
* a script draws. If it never shows up, the call comes back as a timeout at no charge,
|
|
107
|
+
* rather than the half-built page. */
|
|
80
108
|
waitForSelector?: string;
|
|
81
109
|
/** Wait this many milliseconds after the page settles, for the scripts no selector
|
|
82
110
|
* describes. It comes out of `timeoutMs`, never on top of it. */
|
|
@@ -88,11 +116,11 @@ export interface ScrapeParams {
|
|
|
88
116
|
height: number;
|
|
89
117
|
};
|
|
90
118
|
/** Screenshot the whole scrollable page instead of just the window. A long page makes a
|
|
91
|
-
* large answer
|
|
119
|
+
* large answer: the image comes back as base64 inside the response. */
|
|
92
120
|
fullPage?: boolean;
|
|
93
121
|
};
|
|
94
|
-
/** Extra request headers to send to the page
|
|
95
|
-
* agent. The connection's own headers cannot be set. */
|
|
122
|
+
/** Extra request headers to send to the page, such as an authorization token, a cookie or a
|
|
123
|
+
* custom user agent. The connection's own headers cannot be set. */
|
|
96
124
|
headers?: Record<string, string>;
|
|
97
125
|
/** How long to give the page before giving up, in milliseconds. A page that never arrives is a
|
|
98
126
|
* free outcome. */
|
|
@@ -101,36 +129,64 @@ export interface ScrapeParams {
|
|
|
101
129
|
|
|
102
130
|
/** Arguments for `quote()`. */
|
|
103
131
|
export interface QuoteScrapeParams {
|
|
104
|
-
/** The page to read. An http(s) URL
|
|
132
|
+
/** The page to read. An http(s) URL. Private and loopback hosts are refused. */
|
|
105
133
|
url: string;
|
|
106
134
|
/** How to read it. "fetch" is a plain HTTP request; "browser" renders the page in a real
|
|
107
|
-
* Chromium; "auto" fetches first and escalates to the browser when the body
|
|
108
|
-
* JavaScript shell, billing whichever engine answered.
|
|
135
|
+
* Chromium; "auto" (the default) fetches first and escalates to the browser when the body
|
|
136
|
+
* turns out to be a JavaScript shell, billing whichever engine answered. A POST and "raw"
|
|
137
|
+
* always use "fetch", so leave it out for them. */
|
|
109
138
|
engine?: "auto" | "fetch" | "browser";
|
|
110
|
-
/** Whether to try again a different way when the first attempt is blocked.
|
|
111
|
-
* one try
|
|
112
|
-
* call: with `auto`, trying again is what charges the browser price instead of
|
|
139
|
+
/** Whether to try again a different way when the first attempt is blocked. On by default.
|
|
140
|
+
* `false` stops after one try. The site's refusal is your answer, and it costs nothing. It is
|
|
141
|
+
* how you bound a call: with `auto`, trying again is what charges the browser price instead of
|
|
142
|
+
* the fetch one. A POST is sent once, so it is off for a POST. */
|
|
113
143
|
escalate?: boolean;
|
|
144
|
+
/** The HTTP method. "POST" sends `body` to the URL, for a search form or a JSON query. It is
|
|
145
|
+
* sent once: never retried and never sent again another way, because sending it twice could
|
|
146
|
+
* repeat what it did. */
|
|
147
|
+
method?: "GET" | "POST";
|
|
148
|
+
/** What a POST sends, at most 64 KB. Set its type in `headers`: `{"content-type":
|
|
149
|
+
* "application/json"}` for JSON, or `application/x-www-form-urlencoded` for a form. If the
|
|
150
|
+
* site redirects, a 301, 302 or 303 reads the next page with GET and without the body; a 307
|
|
151
|
+
* or 308 sends it again only if the protocol, host and port stay the same, and otherwise stops
|
|
152
|
+
* and names the new address. */
|
|
153
|
+
body?: string;
|
|
114
154
|
/** How many extra tries to give a page the site blocks, each from a different address. 0 (the
|
|
115
155
|
* default) takes the site's first no as the answer. A blocked page costs nothing, so a try
|
|
116
|
-
* that is blocked again is free
|
|
156
|
+
* that is blocked again is free, but it takes as long as the first one did, so the call can
|
|
117
157
|
* run that many times longer. */
|
|
118
158
|
retry?: number;
|
|
119
159
|
/** What to hand back. "screenshot" and "pdf" come back as base64 and need the browser engine;
|
|
120
160
|
* asking for both costs no more than one. "extract" is the page read into fields by a model,
|
|
121
|
-
* and needs an `extract` block saying which ones.
|
|
122
|
-
|
|
161
|
+
* and needs an `extract` block saying which ones. A link to a PDF or a Word (.docx) file is
|
|
162
|
+
* read into text, so the text formats work on it too. We read files up to 25 MB and the first
|
|
163
|
+
* 200 pages, at the fetch price. "raw" is the file exactly as the site sent it, as base64 with
|
|
164
|
+
* its content type: a PDF report, an image, a spreadsheet. It uses the fetch engine and holds
|
|
165
|
+
* up to 5 MB; a larger file answers FILE_TOO_LARGE at no charge, never cut short. */
|
|
166
|
+
formats?: ("markdown" | "html" | "text" | "links" | "screenshot" | "pdf" | "extract" | "raw")[];
|
|
167
|
+
/** Read only the page's main content into `markdown`, `text` and `extract`: the article or the
|
|
168
|
+
* product, without the menus, ads and related links around it. On by default. Set `false` for
|
|
169
|
+
* the whole page. When the main content is under 50 words, you get the whole page instead.
|
|
170
|
+
* `html` and `links` always hold the whole page. */
|
|
171
|
+
onlyMainContent?: boolean;
|
|
172
|
+
/** CSS selectors for the parts of the page to keep, such as `["h1", ".price"]`. `markdown`,
|
|
173
|
+
* `text` and `extract` then hold only what they match, in page order, and `onlyMainContent` no
|
|
174
|
+
* longer applies. Hidden parts are never kept. Up to 20 selectors, 256 characters each. */
|
|
175
|
+
includeTags?: string[];
|
|
176
|
+
/** CSS selectors for the parts of the page to leave out of `markdown`, `text` and `extract`,
|
|
177
|
+
* such as `[".comments", "#newsletter"]`. Up to 20 selectors, 256 characters each. */
|
|
178
|
+
excludeTags?: string[];
|
|
123
179
|
/** What the page should answer with. Set `"json"` when you are reading an API: anything else
|
|
124
|
-
* that comes back
|
|
125
|
-
*
|
|
126
|
-
*
|
|
180
|
+
* that comes back (a maintenance notice, a "checking your browser" page, a login form) is then
|
|
181
|
+
* not your answer. It costs nothing, and we try again from another address instead of handing
|
|
182
|
+
* you a page you cannot parse. Without it, whatever the page returns is your answer. */
|
|
127
183
|
expect?: "json";
|
|
128
184
|
/** What to pull out of the page, for the "extract" format. A model reads the page and fills in
|
|
129
|
-
* the shape you asked for
|
|
185
|
+
* the shape you asked for. Give it a JSON Schema, a sentence, or both. It reads what the page
|
|
130
186
|
* says; it does not do arithmetic over it, so ask for the numbers and add them up in your own
|
|
131
187
|
* code. */
|
|
132
188
|
extract?: {
|
|
133
|
-
/** The shape you want back, as JSON Schema
|
|
189
|
+
/** The shape you want back, as JSON Schema: an object whose properties are the fields you
|
|
134
190
|
* need. A field the page does not mention comes back null; nothing is invented to fill it. */
|
|
135
191
|
schema?: Record<string, unknown>;
|
|
136
192
|
/** What to pull out, in your own words: `the price, the author and the date it was
|
|
@@ -141,7 +197,7 @@ export interface QuoteScrapeParams {
|
|
|
141
197
|
/** Where the request leaves from. Defaults to the managed residential pool. */
|
|
142
198
|
proxy?: {
|
|
143
199
|
/** Which exit to leave through. "residential" is the managed pool, metered by the megabyte;
|
|
144
|
-
* "custom" is your own proxy
|
|
200
|
+
* "custom" is your own proxy, free on every plan, bytes never billed. */
|
|
145
201
|
pool?: "residential" | "custom";
|
|
146
202
|
/** Your own proxy, `http(s)://[user:pass@]host:port`. Required for pool "custom", refused
|
|
147
203
|
* for the managed one. */
|
|
@@ -161,7 +217,7 @@ export interface QuoteScrapeParams {
|
|
|
161
217
|
* charge; ask for the state or the country alone. */
|
|
162
218
|
city?: string;
|
|
163
219
|
};
|
|
164
|
-
/** How to render it. Only the browser engine reads these
|
|
220
|
+
/** How to render it. Only the browser engine reads these. With `auto` they apply if the page
|
|
165
221
|
* turns out to need one. */
|
|
166
222
|
browser?: {
|
|
167
223
|
/** When the page counts as loaded. "load" (the default) waits for images and stylesheets;
|
|
@@ -169,9 +225,9 @@ export interface QuoteScrapeParams {
|
|
|
169
225
|
* page stops asking for things. Every page gets a short settle after this whichever you
|
|
170
226
|
* pick. */
|
|
171
227
|
waitUntil?: "load" | "domcontentloaded" | "networkidle";
|
|
172
|
-
/** Wait until this CSS selector is on the page
|
|
173
|
-
* script draws. If it never shows up the call comes back as a timeout at no charge,
|
|
174
|
-
* than the half-built page. */
|
|
228
|
+
/** Wait until this CSS selector is on the page. It is the dependable way to read something
|
|
229
|
+
* a script draws. If it never shows up, the call comes back as a timeout at no charge,
|
|
230
|
+
* rather than the half-built page. */
|
|
175
231
|
waitForSelector?: string;
|
|
176
232
|
/** Wait this many milliseconds after the page settles, for the scripts no selector
|
|
177
233
|
* describes. It comes out of `timeoutMs`, never on top of it. */
|
|
@@ -183,23 +239,85 @@ export interface QuoteScrapeParams {
|
|
|
183
239
|
height: number;
|
|
184
240
|
};
|
|
185
241
|
/** Screenshot the whole scrollable page instead of just the window. A long page makes a
|
|
186
|
-
* large answer
|
|
242
|
+
* large answer: the image comes back as base64 inside the response. */
|
|
187
243
|
fullPage?: boolean;
|
|
188
244
|
};
|
|
189
|
-
/** Extra request headers to send to the page
|
|
190
|
-
* agent. The connection's own headers cannot be set. */
|
|
245
|
+
/** Extra request headers to send to the page, such as an authorization token, a cookie or a
|
|
246
|
+
* custom user agent. The connection's own headers cannot be set. */
|
|
191
247
|
headers?: Record<string, string>;
|
|
192
248
|
/** How long to give the page before giving up, in milliseconds. A page that never arrives is a
|
|
193
249
|
* free outcome. */
|
|
194
250
|
timeoutMs?: number;
|
|
195
251
|
}
|
|
196
252
|
|
|
253
|
+
/** Arguments for `map()`. */
|
|
254
|
+
export interface MapSiteParams {
|
|
255
|
+
/** The site to map, as any http(s) URL on it. Private and loopback hosts are refused. */
|
|
256
|
+
url: string;
|
|
257
|
+
/** How many URLs to hand back at most, 1 to 30,000. The price is the same whatever you ask for. */
|
|
258
|
+
limit?: number;
|
|
259
|
+
/** Only URLs that contain this text, upper or lower case alike: `blog` keeps `/blog/` and
|
|
260
|
+
* `/Blog-post`. */
|
|
261
|
+
search?: string;
|
|
262
|
+
/** Also keep URLs on other hosts of the same domain, like `blog.example.com` for `example.com`.
|
|
263
|
+
* Off by default: only the host you named, with or without `www.`. */
|
|
264
|
+
includeSubdomains?: boolean;
|
|
265
|
+
/** Where to look. "include" reads the site's sitemaps and the links on the page you named;
|
|
266
|
+
* "only" reads the sitemaps alone; "skip" reads the page's links alone. */
|
|
267
|
+
sitemap?: "include" | "only" | "skip";
|
|
268
|
+
/** Where the map's requests leave from. Every file it reads goes through the same exit. */
|
|
269
|
+
proxy?: {
|
|
270
|
+
/** Which exit to leave through. "residential" is the managed pool, metered by the megabyte;
|
|
271
|
+
* "custom" is your own proxy, free on every plan, bytes never billed. */
|
|
272
|
+
pool?: "residential" | "custom";
|
|
273
|
+
/** Your own proxy, `http(s)://[user:pass@]host:port`. Required for pool "custom", refused
|
|
274
|
+
* for the managed one. */
|
|
275
|
+
server?: string;
|
|
276
|
+
/** Where the call should look like it comes from, ISO 3166-1 alpha-2 (`us`, `br`). Name one
|
|
277
|
+
* and the managed pool leaves from that country. Leave it out and the page sees a US
|
|
278
|
+
* browser, from an address we pick. The browser's clock and languages follow the country
|
|
279
|
+
* on every pool. */
|
|
280
|
+
country?: string;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Arguments for `quoteMap()`. */
|
|
285
|
+
export interface QuoteMapParams {
|
|
286
|
+
/** The site to map, as any http(s) URL on it. Private and loopback hosts are refused. */
|
|
287
|
+
url: string;
|
|
288
|
+
/** How many URLs to hand back at most, 1 to 30,000. The price is the same whatever you ask for. */
|
|
289
|
+
limit?: number;
|
|
290
|
+
/** Only URLs that contain this text, upper or lower case alike: `blog` keeps `/blog/` and
|
|
291
|
+
* `/Blog-post`. */
|
|
292
|
+
search?: string;
|
|
293
|
+
/** Also keep URLs on other hosts of the same domain, like `blog.example.com` for `example.com`.
|
|
294
|
+
* Off by default: only the host you named, with or without `www.`. */
|
|
295
|
+
includeSubdomains?: boolean;
|
|
296
|
+
/** Where to look. "include" reads the site's sitemaps and the links on the page you named;
|
|
297
|
+
* "only" reads the sitemaps alone; "skip" reads the page's links alone. */
|
|
298
|
+
sitemap?: "include" | "only" | "skip";
|
|
299
|
+
/** Where the map's requests leave from. Every file it reads goes through the same exit. */
|
|
300
|
+
proxy?: {
|
|
301
|
+
/** Which exit to leave through. "residential" is the managed pool, metered by the megabyte;
|
|
302
|
+
* "custom" is your own proxy, free on every plan, bytes never billed. */
|
|
303
|
+
pool?: "residential" | "custom";
|
|
304
|
+
/** Your own proxy, `http(s)://[user:pass@]host:port`. Required for pool "custom", refused
|
|
305
|
+
* for the managed one. */
|
|
306
|
+
server?: string;
|
|
307
|
+
/** Where the call should look like it comes from, ISO 3166-1 alpha-2 (`us`, `br`). Name one
|
|
308
|
+
* and the managed pool leaves from that country. Leave it out and the page sees a US
|
|
309
|
+
* browser, from an address we pick. The browser's clock and languages follow the country
|
|
310
|
+
* on every pool. */
|
|
311
|
+
country?: string;
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
197
315
|
/** Arguments for `search()`. */
|
|
198
316
|
export interface SearchParams {
|
|
199
|
-
/** What to search for, in plain words
|
|
317
|
+
/** What to search for, in plain words: the same thing you would type. */
|
|
200
318
|
query: string;
|
|
201
319
|
/** How many results to hand back at most, 1–20. Billed per 10, so asking for more than 10 costs
|
|
202
|
-
* a second row. Fewer can come back than you asked for
|
|
320
|
+
* a second row. Fewer can come back than you asked for: an index has what it has, and
|
|
203
321
|
* `includeDomains` filters what it returns. */
|
|
204
322
|
limit?: number;
|
|
205
323
|
/** What kind of results. "general" is the web; "news" is dated journalism, and the only topic
|
|
@@ -207,18 +325,18 @@ export interface SearchParams {
|
|
|
207
325
|
topic?: "general" | "news";
|
|
208
326
|
/** Only pages from the last day, week, month or year. Absent is any time. */
|
|
209
327
|
timeRange?: "day" | "week" | "month" | "year";
|
|
210
|
-
/** Only results on these hosts, bare (`linkedin.com`)
|
|
328
|
+
/** Only results on these hosts, bare (`linkedin.com`). Subdomains are included. Asked of the
|
|
211
329
|
* search front AND enforced on the answer, so what comes back is on your list whatever the
|
|
212
330
|
* front did with it. */
|
|
213
331
|
includeDomains?: string[];
|
|
214
332
|
/** Also write a short paragraph answering the query from the results, in the query's language.
|
|
215
333
|
* Costs one extra credit; leave it off when your own model reads the snippets. */
|
|
216
334
|
answer?: boolean;
|
|
217
|
-
/** Where the search leaves from. `country` picks the exit AND the market the front answers for
|
|
218
|
-
*
|
|
335
|
+
/** Where the search leaves from. `country` picks the exit AND the market the front answers for.
|
|
336
|
+
* `br` gets Brazilian results in Portuguese. */
|
|
219
337
|
proxy?: {
|
|
220
338
|
/** Which exit to leave through. "residential" is the managed pool, metered by the megabyte;
|
|
221
|
-
* "custom" is your own proxy
|
|
339
|
+
* "custom" is your own proxy, free on every plan, bytes never billed. */
|
|
222
340
|
pool?: "residential" | "custom";
|
|
223
341
|
/** Your own proxy, `http(s)://[user:pass@]host:port`. Required for pool "custom", refused
|
|
224
342
|
* for the managed one. */
|
|
@@ -234,33 +352,51 @@ export interface SearchParams {
|
|
|
234
352
|
/** Arguments for `batches.create()`. */
|
|
235
353
|
export interface CreateBatchParams {
|
|
236
354
|
/** How to read it. "fetch" is a plain HTTP request; "browser" renders the page in a real
|
|
237
|
-
* Chromium; "auto" fetches first and escalates to the browser when the body
|
|
238
|
-
* JavaScript shell, billing whichever engine answered.
|
|
355
|
+
* Chromium; "auto" (the default) fetches first and escalates to the browser when the body
|
|
356
|
+
* turns out to be a JavaScript shell, billing whichever engine answered. A POST and "raw"
|
|
357
|
+
* always use "fetch", so leave it out for them. */
|
|
239
358
|
engine?: "auto" | "fetch" | "browser";
|
|
240
|
-
/** Whether to try again a different way when the first attempt is blocked.
|
|
241
|
-
* one try
|
|
242
|
-
* call: with `auto`, trying again is what charges the browser price instead of
|
|
359
|
+
/** Whether to try again a different way when the first attempt is blocked. On by default.
|
|
360
|
+
* `false` stops after one try. The site's refusal is your answer, and it costs nothing. It is
|
|
361
|
+
* how you bound a call: with `auto`, trying again is what charges the browser price instead of
|
|
362
|
+
* the fetch one. A POST is sent once, so it is off for a POST. */
|
|
243
363
|
escalate?: boolean;
|
|
244
364
|
/** How many extra tries to give a page the site blocks, each from a different address. 0 (the
|
|
245
365
|
* default) takes the site's first no as the answer. A blocked page costs nothing, so a try
|
|
246
|
-
* that is blocked again is free
|
|
366
|
+
* that is blocked again is free, but it takes as long as the first one did, so the call can
|
|
247
367
|
* run that many times longer. */
|
|
248
368
|
retry?: number;
|
|
249
369
|
/** What to hand back. "screenshot" and "pdf" come back as base64 and need the browser engine;
|
|
250
370
|
* asking for both costs no more than one. "extract" is the page read into fields by a model,
|
|
251
|
-
* and needs an `extract` block saying which ones.
|
|
252
|
-
|
|
371
|
+
* and needs an `extract` block saying which ones. A link to a PDF or a Word (.docx) file is
|
|
372
|
+
* read into text, so the text formats work on it too. We read files up to 25 MB and the first
|
|
373
|
+
* 200 pages, at the fetch price. "raw" is the file exactly as the site sent it, as base64 with
|
|
374
|
+
* its content type: a PDF report, an image, a spreadsheet. It uses the fetch engine and holds
|
|
375
|
+
* up to 5 MB; a larger file answers FILE_TOO_LARGE at no charge, never cut short. */
|
|
376
|
+
formats?: ("markdown" | "html" | "text" | "links" | "screenshot" | "pdf" | "extract" | "raw")[];
|
|
377
|
+
/** Read only the page's main content into `markdown`, `text` and `extract`: the article or the
|
|
378
|
+
* product, without the menus, ads and related links around it. On by default. Set `false` for
|
|
379
|
+
* the whole page. When the main content is under 50 words, you get the whole page instead.
|
|
380
|
+
* `html` and `links` always hold the whole page. */
|
|
381
|
+
onlyMainContent?: boolean;
|
|
382
|
+
/** CSS selectors for the parts of the page to keep, such as `["h1", ".price"]`. `markdown`,
|
|
383
|
+
* `text` and `extract` then hold only what they match, in page order, and `onlyMainContent` no
|
|
384
|
+
* longer applies. Hidden parts are never kept. Up to 20 selectors, 256 characters each. */
|
|
385
|
+
includeTags?: string[];
|
|
386
|
+
/** CSS selectors for the parts of the page to leave out of `markdown`, `text` and `extract`,
|
|
387
|
+
* such as `[".comments", "#newsletter"]`. Up to 20 selectors, 256 characters each. */
|
|
388
|
+
excludeTags?: string[];
|
|
253
389
|
/** What the page should answer with. Set `"json"` when you are reading an API: anything else
|
|
254
|
-
* that comes back
|
|
255
|
-
*
|
|
256
|
-
*
|
|
390
|
+
* that comes back (a maintenance notice, a "checking your browser" page, a login form) is then
|
|
391
|
+
* not your answer. It costs nothing, and we try again from another address instead of handing
|
|
392
|
+
* you a page you cannot parse. Without it, whatever the page returns is your answer. */
|
|
257
393
|
expect?: "json";
|
|
258
394
|
/** What to pull out of the page, for the "extract" format. A model reads the page and fills in
|
|
259
|
-
* the shape you asked for
|
|
395
|
+
* the shape you asked for. Give it a JSON Schema, a sentence, or both. It reads what the page
|
|
260
396
|
* says; it does not do arithmetic over it, so ask for the numbers and add them up in your own
|
|
261
397
|
* code. */
|
|
262
398
|
extract?: {
|
|
263
|
-
/** The shape you want back, as JSON Schema
|
|
399
|
+
/** The shape you want back, as JSON Schema: an object whose properties are the fields you
|
|
264
400
|
* need. A field the page does not mention comes back null; nothing is invented to fill it. */
|
|
265
401
|
schema?: Record<string, unknown>;
|
|
266
402
|
/** What to pull out, in your own words: `the price, the author and the date it was
|
|
@@ -271,7 +407,7 @@ export interface CreateBatchParams {
|
|
|
271
407
|
/** Where the request leaves from. Defaults to the managed residential pool. */
|
|
272
408
|
proxy?: {
|
|
273
409
|
/** Which exit to leave through. "residential" is the managed pool, metered by the megabyte;
|
|
274
|
-
* "custom" is your own proxy
|
|
410
|
+
* "custom" is your own proxy, free on every plan, bytes never billed. */
|
|
275
411
|
pool?: "residential" | "custom";
|
|
276
412
|
/** Your own proxy, `http(s)://[user:pass@]host:port`. Required for pool "custom", refused
|
|
277
413
|
* for the managed one. */
|
|
@@ -291,7 +427,7 @@ export interface CreateBatchParams {
|
|
|
291
427
|
* charge; ask for the state or the country alone. */
|
|
292
428
|
city?: string;
|
|
293
429
|
};
|
|
294
|
-
/** How to render it. Only the browser engine reads these
|
|
430
|
+
/** How to render it. Only the browser engine reads these. With `auto` they apply if the page
|
|
295
431
|
* turns out to need one. */
|
|
296
432
|
browser?: {
|
|
297
433
|
/** When the page counts as loaded. "load" (the default) waits for images and stylesheets;
|
|
@@ -299,9 +435,9 @@ export interface CreateBatchParams {
|
|
|
299
435
|
* page stops asking for things. Every page gets a short settle after this whichever you
|
|
300
436
|
* pick. */
|
|
301
437
|
waitUntil?: "load" | "domcontentloaded" | "networkidle";
|
|
302
|
-
/** Wait until this CSS selector is on the page
|
|
303
|
-
* script draws. If it never shows up the call comes back as a timeout at no charge,
|
|
304
|
-
* than the half-built page. */
|
|
438
|
+
/** Wait until this CSS selector is on the page. It is the dependable way to read something
|
|
439
|
+
* a script draws. If it never shows up, the call comes back as a timeout at no charge,
|
|
440
|
+
* rather than the half-built page. */
|
|
305
441
|
waitForSelector?: string;
|
|
306
442
|
/** Wait this many milliseconds after the page settles, for the scripts no selector
|
|
307
443
|
* describes. It comes out of `timeoutMs`, never on top of it. */
|
|
@@ -313,11 +449,11 @@ export interface CreateBatchParams {
|
|
|
313
449
|
height: number;
|
|
314
450
|
};
|
|
315
451
|
/** Screenshot the whole scrollable page instead of just the window. A long page makes a
|
|
316
|
-
* large answer
|
|
452
|
+
* large answer: the image comes back as base64 inside the response. */
|
|
317
453
|
fullPage?: boolean;
|
|
318
454
|
};
|
|
319
|
-
/** Extra request headers to send to the page
|
|
320
|
-
* agent. The connection's own headers cannot be set. */
|
|
455
|
+
/** Extra request headers to send to the page, such as an authorization token, a cookie or a
|
|
456
|
+
* custom user agent. The connection's own headers cannot be set. */
|
|
321
457
|
headers?: Record<string, string>;
|
|
322
458
|
/** How long to give the page before giving up, in milliseconds. A page that never arrives is a
|
|
323
459
|
* free outcome. */
|
|
@@ -334,8 +470,8 @@ export interface CreateBatchParams {
|
|
|
334
470
|
url: string;
|
|
335
471
|
/** What to call about. "batch.completed" fires once: when every URL has a verdict, or when
|
|
336
472
|
* we could not finish the batch. `batch.status` says which: `completed` or `failed`.
|
|
337
|
-
* "batch.item.completed" fires per URL
|
|
338
|
-
*
|
|
473
|
+
* "batch.item.completed" fires per URL, with one request from us per item. That makes a
|
|
474
|
+
* long batch usable before it ends, so ask for it deliberately. */
|
|
339
475
|
events?: ("batch.completed" | "batch.item.completed")[];
|
|
340
476
|
};
|
|
341
477
|
}
|
|
@@ -343,33 +479,51 @@ export interface CreateBatchParams {
|
|
|
343
479
|
/** Arguments for `batches.quote()`. */
|
|
344
480
|
export interface QuoteBatchParams {
|
|
345
481
|
/** How to read it. "fetch" is a plain HTTP request; "browser" renders the page in a real
|
|
346
|
-
* Chromium; "auto" fetches first and escalates to the browser when the body
|
|
347
|
-
* JavaScript shell, billing whichever engine answered.
|
|
482
|
+
* Chromium; "auto" (the default) fetches first and escalates to the browser when the body
|
|
483
|
+
* turns out to be a JavaScript shell, billing whichever engine answered. A POST and "raw"
|
|
484
|
+
* always use "fetch", so leave it out for them. */
|
|
348
485
|
engine?: "auto" | "fetch" | "browser";
|
|
349
|
-
/** Whether to try again a different way when the first attempt is blocked.
|
|
350
|
-
* one try
|
|
351
|
-
* call: with `auto`, trying again is what charges the browser price instead of
|
|
486
|
+
/** Whether to try again a different way when the first attempt is blocked. On by default.
|
|
487
|
+
* `false` stops after one try. The site's refusal is your answer, and it costs nothing. It is
|
|
488
|
+
* how you bound a call: with `auto`, trying again is what charges the browser price instead of
|
|
489
|
+
* the fetch one. A POST is sent once, so it is off for a POST. */
|
|
352
490
|
escalate?: boolean;
|
|
353
491
|
/** How many extra tries to give a page the site blocks, each from a different address. 0 (the
|
|
354
492
|
* default) takes the site's first no as the answer. A blocked page costs nothing, so a try
|
|
355
|
-
* that is blocked again is free
|
|
493
|
+
* that is blocked again is free, but it takes as long as the first one did, so the call can
|
|
356
494
|
* run that many times longer. */
|
|
357
495
|
retry?: number;
|
|
358
496
|
/** What to hand back. "screenshot" and "pdf" come back as base64 and need the browser engine;
|
|
359
497
|
* asking for both costs no more than one. "extract" is the page read into fields by a model,
|
|
360
|
-
* and needs an `extract` block saying which ones.
|
|
361
|
-
|
|
498
|
+
* and needs an `extract` block saying which ones. A link to a PDF or a Word (.docx) file is
|
|
499
|
+
* read into text, so the text formats work on it too. We read files up to 25 MB and the first
|
|
500
|
+
* 200 pages, at the fetch price. "raw" is the file exactly as the site sent it, as base64 with
|
|
501
|
+
* its content type: a PDF report, an image, a spreadsheet. It uses the fetch engine and holds
|
|
502
|
+
* up to 5 MB; a larger file answers FILE_TOO_LARGE at no charge, never cut short. */
|
|
503
|
+
formats?: ("markdown" | "html" | "text" | "links" | "screenshot" | "pdf" | "extract" | "raw")[];
|
|
504
|
+
/** Read only the page's main content into `markdown`, `text` and `extract`: the article or the
|
|
505
|
+
* product, without the menus, ads and related links around it. On by default. Set `false` for
|
|
506
|
+
* the whole page. When the main content is under 50 words, you get the whole page instead.
|
|
507
|
+
* `html` and `links` always hold the whole page. */
|
|
508
|
+
onlyMainContent?: boolean;
|
|
509
|
+
/** CSS selectors for the parts of the page to keep, such as `["h1", ".price"]`. `markdown`,
|
|
510
|
+
* `text` and `extract` then hold only what they match, in page order, and `onlyMainContent` no
|
|
511
|
+
* longer applies. Hidden parts are never kept. Up to 20 selectors, 256 characters each. */
|
|
512
|
+
includeTags?: string[];
|
|
513
|
+
/** CSS selectors for the parts of the page to leave out of `markdown`, `text` and `extract`,
|
|
514
|
+
* such as `[".comments", "#newsletter"]`. Up to 20 selectors, 256 characters each. */
|
|
515
|
+
excludeTags?: string[];
|
|
362
516
|
/** What the page should answer with. Set `"json"` when you are reading an API: anything else
|
|
363
|
-
* that comes back
|
|
364
|
-
*
|
|
365
|
-
*
|
|
517
|
+
* that comes back (a maintenance notice, a "checking your browser" page, a login form) is then
|
|
518
|
+
* not your answer. It costs nothing, and we try again from another address instead of handing
|
|
519
|
+
* you a page you cannot parse. Without it, whatever the page returns is your answer. */
|
|
366
520
|
expect?: "json";
|
|
367
521
|
/** What to pull out of the page, for the "extract" format. A model reads the page and fills in
|
|
368
|
-
* the shape you asked for
|
|
522
|
+
* the shape you asked for. Give it a JSON Schema, a sentence, or both. It reads what the page
|
|
369
523
|
* says; it does not do arithmetic over it, so ask for the numbers and add them up in your own
|
|
370
524
|
* code. */
|
|
371
525
|
extract?: {
|
|
372
|
-
/** The shape you want back, as JSON Schema
|
|
526
|
+
/** The shape you want back, as JSON Schema: an object whose properties are the fields you
|
|
373
527
|
* need. A field the page does not mention comes back null; nothing is invented to fill it. */
|
|
374
528
|
schema?: Record<string, unknown>;
|
|
375
529
|
/** What to pull out, in your own words: `the price, the author and the date it was
|
|
@@ -380,7 +534,7 @@ export interface QuoteBatchParams {
|
|
|
380
534
|
/** Where the request leaves from. Defaults to the managed residential pool. */
|
|
381
535
|
proxy?: {
|
|
382
536
|
/** Which exit to leave through. "residential" is the managed pool, metered by the megabyte;
|
|
383
|
-
* "custom" is your own proxy
|
|
537
|
+
* "custom" is your own proxy, free on every plan, bytes never billed. */
|
|
384
538
|
pool?: "residential" | "custom";
|
|
385
539
|
/** Your own proxy, `http(s)://[user:pass@]host:port`. Required for pool "custom", refused
|
|
386
540
|
* for the managed one. */
|
|
@@ -400,7 +554,7 @@ export interface QuoteBatchParams {
|
|
|
400
554
|
* charge; ask for the state or the country alone. */
|
|
401
555
|
city?: string;
|
|
402
556
|
};
|
|
403
|
-
/** How to render it. Only the browser engine reads these
|
|
557
|
+
/** How to render it. Only the browser engine reads these. With `auto` they apply if the page
|
|
404
558
|
* turns out to need one. */
|
|
405
559
|
browser?: {
|
|
406
560
|
/** When the page counts as loaded. "load" (the default) waits for images and stylesheets;
|
|
@@ -408,9 +562,9 @@ export interface QuoteBatchParams {
|
|
|
408
562
|
* page stops asking for things. Every page gets a short settle after this whichever you
|
|
409
563
|
* pick. */
|
|
410
564
|
waitUntil?: "load" | "domcontentloaded" | "networkidle";
|
|
411
|
-
/** Wait until this CSS selector is on the page
|
|
412
|
-
* script draws. If it never shows up the call comes back as a timeout at no charge,
|
|
413
|
-
* than the half-built page. */
|
|
565
|
+
/** Wait until this CSS selector is on the page. It is the dependable way to read something
|
|
566
|
+
* a script draws. If it never shows up, the call comes back as a timeout at no charge,
|
|
567
|
+
* rather than the half-built page. */
|
|
414
568
|
waitForSelector?: string;
|
|
415
569
|
/** Wait this many milliseconds after the page settles, for the scripts no selector
|
|
416
570
|
* describes. It comes out of `timeoutMs`, never on top of it. */
|
|
@@ -422,11 +576,11 @@ export interface QuoteBatchParams {
|
|
|
422
576
|
height: number;
|
|
423
577
|
};
|
|
424
578
|
/** Screenshot the whole scrollable page instead of just the window. A long page makes a
|
|
425
|
-
* large answer
|
|
579
|
+
* large answer: the image comes back as base64 inside the response. */
|
|
426
580
|
fullPage?: boolean;
|
|
427
581
|
};
|
|
428
|
-
/** Extra request headers to send to the page
|
|
429
|
-
* agent. The connection's own headers cannot be set. */
|
|
582
|
+
/** Extra request headers to send to the page, such as an authorization token, a cookie or a
|
|
583
|
+
* custom user agent. The connection's own headers cannot be set. */
|
|
430
584
|
headers?: Record<string, string>;
|
|
431
585
|
/** How long to give the page before giving up, in milliseconds. A page that never arrives is a
|
|
432
586
|
* free outcome. */
|
|
@@ -443,8 +597,8 @@ export interface QuoteBatchParams {
|
|
|
443
597
|
url: string;
|
|
444
598
|
/** What to call about. "batch.completed" fires once: when every URL has a verdict, or when
|
|
445
599
|
* we could not finish the batch. `batch.status` says which: `completed` or `failed`.
|
|
446
|
-
* "batch.item.completed" fires per URL
|
|
447
|
-
*
|
|
600
|
+
* "batch.item.completed" fires per URL, with one request from us per item. That makes a
|
|
601
|
+
* long batch usable before it ends, so ask for it deliberately. */
|
|
448
602
|
events?: ("batch.completed" | "batch.item.completed")[];
|
|
449
603
|
};
|
|
450
604
|
}
|
|
@@ -483,7 +637,7 @@ export interface CreateSessionParams {
|
|
|
483
637
|
* pool. */
|
|
484
638
|
proxy?: {
|
|
485
639
|
/** Which exit to leave through. "residential" is the managed pool, metered by the megabyte;
|
|
486
|
-
* "custom" is your own proxy
|
|
640
|
+
* "custom" is your own proxy, free on every plan, bytes never billed. */
|
|
487
641
|
pool?: "residential" | "custom";
|
|
488
642
|
/** Your own proxy, `http(s)://[user:pass@]host:port`. Required for pool "custom", refused
|
|
489
643
|
* for the managed one. */
|
|
@@ -515,7 +669,7 @@ export interface QuoteSessionParams {
|
|
|
515
669
|
* pool. */
|
|
516
670
|
proxy?: {
|
|
517
671
|
/** Which exit to leave through. "residential" is the managed pool, metered by the megabyte;
|
|
518
|
-
* "custom" is your own proxy
|
|
672
|
+
* "custom" is your own proxy, free on every plan, bytes never billed. */
|
|
519
673
|
pool?: "residential" | "custom";
|
|
520
674
|
/** Your own proxy, `http(s)://[user:pass@]host:port`. Required for pool "custom", refused
|
|
521
675
|
* for the managed one. */
|