@mrscraper/sdk 4.0.1 → 6.0.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 +503 -204
- package/dist/api.d.ts +113 -102
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +187 -231
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,307 +1,606 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MrScraper Node SDK
|
|
2
2
|
|
|
3
|
-

|
|
3
|
+

|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
An async JavaScript and TypeScript SDK for the seven MrScraper services.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
Seven services share the same descriptions, parameter meanings, and defaults across the CLI, SDKs, and integrations. Names, types, authentication, and code examples follow each surface's conventions. See the [API Reference](https://docs.mrscraper.com/docs/api/overview).
|
|
10
|
+
|
|
11
|
+
| Service | Public name | Description |
|
|
12
|
+
| ----------------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| [Status](#status) | `status` | Return the raw account status API response without summarizing, redacting body fields, or adding calculated fields. |
|
|
14
|
+
| [Scrape HTML](#scrape-html) | `scrapeHtml` | Retrieve the raw HTML of a page. Browser rendering is optional. |
|
|
15
|
+
| [Scrape Markdown](#scrape-markdown) | `scrapeMarkdown` | Retrieve a page as Markdown. Including HTML also enables browser rendering and returns both outputs as JSON. |
|
|
16
|
+
| [Get screenshot](#get-screenshot) | `getScreenshot` | Capture a base64 screenshot of the full page or top viewport. Browser rendering is always enabled. |
|
|
17
|
+
| [Scrape brand](#scrape-brand) | `scrapeBrand` | Extract a website's colors, typography, logos, and social links as JSON. |
|
|
18
|
+
| [Scrape JSON](#scrape-json) | `scrapeJson` | Extract structured JSON from a page using a natural-language prompt. Append Json Schema: and a JSON schema to shape the output. |
|
|
19
|
+
| [Web search](#web-search) | `webSearch` | Search the web and return ranked results with titles, URLs, descriptions, and sources. |
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Requires Node.js 18 or newer. Examples use ES modules; save executable examples as `.mjs` files or set `"type": "module"` in your package.
|
|
8
24
|
|
|
9
25
|
```bash
|
|
10
26
|
npm install @mrscraper/sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Authentication
|
|
30
|
+
|
|
31
|
+
Obtain an API key from [the MrScraper app](https://app.mrscraper.com/api-tokens). API key used to authenticate the request.
|
|
32
|
+
|
|
33
|
+
```bash
|
|
11
34
|
export MRSCRAPER_API_TOKEN="YOUR_TOKEN"
|
|
12
35
|
```
|
|
13
36
|
|
|
14
|
-
|
|
37
|
+
Each function accepts an optional `token: string` in its options. Precedence is a nonempty explicit token, `MRSCRAPER_API_TOKEN`, then `MRSCRAPER_API_KEY`. Credentials are sent in headers, never in the request URL.
|
|
15
38
|
|
|
16
|
-
##
|
|
39
|
+
## Quickstart
|
|
17
40
|
|
|
18
|
-
|
|
41
|
+
```js
|
|
42
|
+
import { scrapeHtml } from "@mrscraper/sdk";
|
|
19
43
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
| `get_brand(job_id, options)` | Read a job by `job_id`; optional `output` downloads a file |
|
|
30
|
-
| `web_search(url, options)` | Retrieve real-time web search results |
|
|
31
|
-
| `account(options)` | Read account identity, subscription, quota, and rate limits |
|
|
44
|
+
const result = await scrapeHtml("https://example.com", {
|
|
45
|
+
browserRendering: true,
|
|
46
|
+
warmStart: true,
|
|
47
|
+
waitForSelector: "body",
|
|
48
|
+
timeout: 120,
|
|
49
|
+
maxRetries: 0,
|
|
50
|
+
});
|
|
51
|
+
console.log(result.data);
|
|
52
|
+
```
|
|
32
53
|
|
|
33
|
-
|
|
54
|
+
Examples use `example.com` as the sample target. Replace it for your use case. Live scraping and search calls consume account quota.
|
|
34
55
|
|
|
35
|
-
|
|
56
|
+
Response examples show selected keys and types observed in live API responses. Values are placeholders; page content, base64 images, and arrays are abbreviated. Actual responses may contain additional fields.
|
|
36
57
|
|
|
37
|
-
|
|
38
|
-
import { scraper_html, scraper_markdown, get_screenshot } from "@mrscraper/sdk";
|
|
58
|
+
## Shared parameters
|
|
39
59
|
|
|
40
|
-
|
|
41
|
-
// Previously: scraper_api(url, { html: true })
|
|
42
|
-
const html = await scraper_html(url);
|
|
43
|
-
// Previously: scraper_api(url, { html: false, markdown: true })
|
|
44
|
-
const markdown = await scraper_markdown(url);
|
|
45
|
-
// Previously: scraper_api(url, { screenshot: true })
|
|
46
|
-
const screenshot = await get_screenshot(url);
|
|
47
|
-
```
|
|
60
|
+
### Page controls
|
|
48
61
|
|
|
49
|
-
|
|
62
|
+
HTML, Markdown, screenshots, and JSON extraction share `url`, `timeout`, `geoCode`, `proxyCountry`, `super`, `waitUntil`, `proxy`, `maxRetries`, and `saveResult` (using the naming style shown below). Page defaults are 300 seconds, US geolocation/proxy country, real-device routing off, and dashboard saving off. Omitted retry limits mean no limit. Exact types, defaults, and standard descriptions appear in each service table.
|
|
50
63
|
|
|
51
|
-
|
|
64
|
+
### Loading controls
|
|
52
65
|
|
|
53
|
-
|
|
66
|
+
HTML, Markdown, and screenshots additionally accept `blockResources`, `waitForSelector`, and `returnCookie`. JSON extraction does not accept these controls. Browser rendering is optional for HTML, Markdown, and JSON; screenshots always enable it. Markdown with HTML also enables browser rendering.
|
|
54
67
|
|
|
55
|
-
|
|
56
|
-
import { scraper_html, scraper_markdown } from "@mrscraper/sdk";
|
|
68
|
+
## Service reference
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
const markdown = await scraper_markdown("https://example.com", { home_page: true });
|
|
60
|
-
console.log(html.data, markdown.data);
|
|
61
|
-
```
|
|
70
|
+
### Status
|
|
62
71
|
|
|
63
|
-
|
|
72
|
+
#### Description
|
|
64
73
|
|
|
65
|
-
|
|
74
|
+
Return the raw account status API response without summarizing, redacting body fields, or adding calculated fields.
|
|
66
75
|
|
|
67
|
-
|
|
68
|
-
|--------|---------|-------------|
|
|
69
|
-
| `token` | Environment variable | API token override |
|
|
70
|
-
| `timeout` | `120` (`300` for screenshots) | Page timeout in seconds, from 1 to 300; HTTP timeout is 30 seconds longer |
|
|
71
|
-
| `geo_code`, `proxy_country` | `"US"`, unset | Geolocation and optional proxy country |
|
|
72
|
-
| `browser_rendering` | unset | `true` to force a browser, `false` to disable it, unset for automatic fallback; unavailable for screenshots, which always enable rendering |
|
|
73
|
-
| `super` | `false` | Enable real device routing |
|
|
74
|
-
| `use_proxy`, `proxy` | `true`, unset | Allow a proxy or supply `username:password@host:port` |
|
|
75
|
-
| `home_page` | `false` | Visit the site's root before the target page |
|
|
76
|
-
| `wait_for_selector` | unset | Wait for a CSS selector |
|
|
77
|
-
| `wait_until` | unset (`"domcontentloaded"` for screenshots) | Browser navigation wait condition; `null` omits it |
|
|
78
|
-
| `block_resources`, `bypass_proxy` | `false`, `false` | Block resources or enable proxy bypass behavior |
|
|
79
|
-
| `cookie_jar`, `headers` | unset | Cookie configuration and target request headers; `headers` accepts an object or JSON string |
|
|
80
|
-
| `max_retries`, `token_cap` | `3`, unset | Nonnegative integer retry count and optional token budget |
|
|
81
|
-
| `stream` | unset | Request a streamed response, buffered into the normal return value |
|
|
82
|
-
| `discard_token_secret` | `""` | Value for the `x-discard-token-secret` API header |
|
|
76
|
+
#### Parameters
|
|
83
77
|
|
|
84
|
-
|
|
78
|
+
This service takes no service parameters. Authentication is configured separately.
|
|
85
79
|
|
|
86
|
-
|
|
80
|
+
The HTTP deadline is fixed at 600 seconds. It is not a service parameter.
|
|
87
81
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
#### Example
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
import { status } from "@mrscraper/sdk";
|
|
86
|
+
|
|
87
|
+
const result = await status();
|
|
88
|
+
console.log(result.data);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### Response
|
|
92
|
+
|
|
93
|
+
The API body contains message and data. Account details remain nested in data, including subscriptionItem and scraperAllowance. The response envelope therefore exposes account details at data.data. Sensitive response headers are removed.
|
|
94
|
+
|
|
95
|
+
**Success response**
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"status_code": 200,
|
|
100
|
+
"data": {
|
|
101
|
+
"message": "Example response",
|
|
102
|
+
"data": {
|
|
103
|
+
"id": "ACCOUNT_ID",
|
|
104
|
+
"tokenLimit": 100000,
|
|
105
|
+
"tokenUsage": 2500,
|
|
106
|
+
"stripeStatus": "active",
|
|
107
|
+
"user": {
|
|
108
|
+
"name": "Example user",
|
|
109
|
+
"email": "user@example.com",
|
|
110
|
+
"isVerified": true
|
|
111
|
+
},
|
|
112
|
+
"subscriptionItem": {
|
|
113
|
+
"name": "Example plan",
|
|
114
|
+
"tokenLimit": 100000
|
|
115
|
+
},
|
|
116
|
+
"scraperAllowance": {
|
|
117
|
+
"remaining": 97500,
|
|
118
|
+
"plans": [
|
|
119
|
+
{
|
|
120
|
+
"remaining": 97500
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"headers": {
|
|
127
|
+
"content-type": "application/json; charset=utf-8"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
91
131
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
132
|
+
### Scrape HTML
|
|
133
|
+
|
|
134
|
+
#### Description
|
|
135
|
+
|
|
136
|
+
Retrieve the raw HTML of a page. Browser rendering is optional.
|
|
137
|
+
|
|
138
|
+
#### Parameters
|
|
139
|
+
|
|
140
|
+
| Parameter | HTTP field | Type | Default | Description |
|
|
141
|
+
| ------------------ | ------------------ | ------------------------------------------------------------------ | -------------------- | ----------------------------------------------------------------------------------------------- |
|
|
142
|
+
| `url` | `url` | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
|
|
143
|
+
| `timeout` | `timeout` | number (integer) | `300` | Page load timeout in seconds, from 1 to 300. The HTTP request allows 30 additional seconds. |
|
|
144
|
+
| `geoCode` | `geoCode` | string | `"us"` | Two-letter country code to load the page from, sent in lowercase. |
|
|
145
|
+
| `proxyCountry` | `proxyCountry` | string | `"us"` | Two-letter country code of the proxy server, sent in lowercase. |
|
|
146
|
+
| `super` | `super` | boolean | `false` | Whether to route the request through real devices. |
|
|
147
|
+
| `waitUntil` | `waitUntil` | string: `domcontentloaded`, `load`, `networkidle0`, `networkidle2` | `"domcontentloaded"` | Navigation completion event to wait for: domcontentloaded, load, networkidle0, or networkidle2. |
|
|
148
|
+
| `proxy` | `proxy` | string | Omitted | Custom proxy URL used to load the page. |
|
|
149
|
+
| `maxRetries` | `maxRetries` | number (integer) | Omitted | Maximum number of retries, as a nonnegative integer. Omit this parameter for no limit. |
|
|
150
|
+
| `saveResult` | `saveResult` | boolean | `false` | Whether to save the result to the dashboard Result tab. |
|
|
151
|
+
| `blockResources` | `blockResources` | boolean | `false` | Whether to block images, fonts, and stylesheets while loading the page. |
|
|
152
|
+
| `waitForSelector` | `waitForSelector` | string | Omitted | Wait for the page to contain the specified CSS selector before returning the result. |
|
|
153
|
+
| `returnCookie` | `returnCookie` | boolean | `false` | Whether to include browser session cookies in the response. |
|
|
154
|
+
| `browserRendering` | `browserRendering` | boolean | `false` | Whether to render the page in a browser before returning the result. |
|
|
155
|
+
| `warmStart` | `warmStart` | boolean | `false` | Whether to enable warm start for more reliable scraping, at the cost of additional latency. |
|
|
156
|
+
|
|
157
|
+
#### Example
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
import { scrapeHtml } from "@mrscraper/sdk";
|
|
161
|
+
|
|
162
|
+
const result = await scrapeHtml("https://example.com", {
|
|
163
|
+
browserRendering: true,
|
|
164
|
+
warmStart: true,
|
|
165
|
+
waitForSelector: "body",
|
|
166
|
+
timeout: 120,
|
|
167
|
+
maxRetries: 0,
|
|
95
168
|
});
|
|
96
|
-
|
|
97
|
-
else console.log(result.data); // The API may also return JSON metadata.
|
|
169
|
+
console.log(result.data);
|
|
98
170
|
```
|
|
99
171
|
|
|
100
|
-
|
|
172
|
+
#### Response
|
|
101
173
|
|
|
102
|
-
|
|
103
|
-
import { scraper_json, scraper_multiple_page } from "@mrscraper/sdk";
|
|
174
|
+
The default response body is HTML text. Additional controls can cause the API to return JSON; the returned structure is preserved.
|
|
104
175
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
176
|
+
**Success response**
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"status_code": 200,
|
|
181
|
+
"data": "<html><body>Example page content...</body></html>",
|
|
182
|
+
"headers": {
|
|
183
|
+
"content-type": "text/html; charset=utf-8"
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Scrape Markdown
|
|
189
|
+
|
|
190
|
+
#### Description
|
|
191
|
+
|
|
192
|
+
Retrieve a page as Markdown. Including HTML also enables browser rendering and returns both outputs as JSON.
|
|
193
|
+
|
|
194
|
+
#### Parameters
|
|
195
|
+
|
|
196
|
+
| Parameter | HTTP field | Type | Default | Description |
|
|
197
|
+
| ------------------ | ------------------ | ------------------------------------------------------------------ | -------------------- | ----------------------------------------------------------------------------------------------- |
|
|
198
|
+
| `url` | `url` | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
|
|
199
|
+
| `timeout` | `timeout` | number (integer) | `300` | Page load timeout in seconds, from 1 to 300. The HTTP request allows 30 additional seconds. |
|
|
200
|
+
| `geoCode` | `geoCode` | string | `"us"` | Two-letter country code to load the page from, sent in lowercase. |
|
|
201
|
+
| `proxyCountry` | `proxyCountry` | string | `"us"` | Two-letter country code of the proxy server, sent in lowercase. |
|
|
202
|
+
| `super` | `super` | boolean | `false` | Whether to route the request through real devices. |
|
|
203
|
+
| `waitUntil` | `waitUntil` | string: `domcontentloaded`, `load`, `networkidle0`, `networkidle2` | `"domcontentloaded"` | Navigation completion event to wait for: domcontentloaded, load, networkidle0, or networkidle2. |
|
|
204
|
+
| `proxy` | `proxy` | string | Omitted | Custom proxy URL used to load the page. |
|
|
205
|
+
| `maxRetries` | `maxRetries` | number (integer) | Omitted | Maximum number of retries, as a nonnegative integer. Omit this parameter for no limit. |
|
|
206
|
+
| `saveResult` | `saveResult` | boolean | `false` | Whether to save the result to the dashboard Result tab. |
|
|
207
|
+
| `blockResources` | `blockResources` | boolean | `false` | Whether to block images, fonts, and stylesheets while loading the page. |
|
|
208
|
+
| `waitForSelector` | `waitForSelector` | string | Omitted | Wait for the page to contain the specified CSS selector before returning the result. |
|
|
209
|
+
| `returnCookie` | `returnCookie` | boolean | `false` | Whether to include browser session cookies in the response. |
|
|
210
|
+
| `browserRendering` | `browserRendering` | boolean | `false` | Whether to render the page in a browser before returning the result. |
|
|
211
|
+
| `warmStart` | `warmStart` | boolean | `false` | Whether to enable warm start for more reliable scraping, at the cost of additional latency. |
|
|
212
|
+
| `html` | `html` | boolean | `false` | Whether to include the page HTML in the response. |
|
|
213
|
+
|
|
214
|
+
#### Example
|
|
215
|
+
|
|
216
|
+
```js
|
|
217
|
+
import { scrapeMarkdown } from "@mrscraper/sdk";
|
|
218
|
+
|
|
219
|
+
const result = await scrapeMarkdown("https://example.com", {
|
|
220
|
+
html: true,
|
|
221
|
+
warmStart: true,
|
|
112
222
|
});
|
|
113
|
-
console.log(
|
|
223
|
+
console.log(result.data);
|
|
114
224
|
```
|
|
115
225
|
|
|
116
|
-
|
|
226
|
+
#### Response
|
|
227
|
+
|
|
228
|
+
The default response body is Markdown text. Enabling HTML returns JSON containing both HTML and Markdown.
|
|
117
229
|
|
|
118
|
-
|
|
230
|
+
**With html enabled**
|
|
119
231
|
|
|
120
|
-
```
|
|
121
|
-
|
|
232
|
+
```json
|
|
233
|
+
{
|
|
234
|
+
"status_code": 200,
|
|
235
|
+
"data": {
|
|
236
|
+
"html": "<html>...</html>",
|
|
237
|
+
"markdown": "# Example page\n\n..."
|
|
238
|
+
},
|
|
239
|
+
"headers": {
|
|
240
|
+
"content-type": "application/json"
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
122
244
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
245
|
+
**Default Markdown text**
|
|
246
|
+
|
|
247
|
+
```json
|
|
248
|
+
{
|
|
249
|
+
"status_code": 200,
|
|
250
|
+
"data": "# Example page\n\nExample Markdown content...",
|
|
251
|
+
"headers": {
|
|
252
|
+
"content-type": "text/markdown; charset=utf-8"
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Get screenshot
|
|
258
|
+
|
|
259
|
+
#### Description
|
|
260
|
+
|
|
261
|
+
Capture a base64 screenshot of the full page or top viewport. Browser rendering is always enabled.
|
|
262
|
+
|
|
263
|
+
#### Parameters
|
|
264
|
+
|
|
265
|
+
| Parameter | HTTP field | Type | Default | Description |
|
|
266
|
+
| ----------------- | ----------------- | ------------------------------------------------------------------ | -------------------- | ----------------------------------------------------------------------------------------------- |
|
|
267
|
+
| `url` | `url` | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
|
|
268
|
+
| `timeout` | `timeout` | number (integer) | `300` | Page load timeout in seconds, from 1 to 300. The HTTP request allows 30 additional seconds. |
|
|
269
|
+
| `geoCode` | `geoCode` | string | `"us"` | Two-letter country code to load the page from, sent in lowercase. |
|
|
270
|
+
| `proxyCountry` | `proxyCountry` | string | `"us"` | Two-letter country code of the proxy server, sent in lowercase. |
|
|
271
|
+
| `super` | `super` | boolean | `false` | Whether to route the request through real devices. |
|
|
272
|
+
| `waitUntil` | `waitUntil` | string: `domcontentloaded`, `load`, `networkidle0`, `networkidle2` | `"domcontentloaded"` | Navigation completion event to wait for: domcontentloaded, load, networkidle0, or networkidle2. |
|
|
273
|
+
| `proxy` | `proxy` | string | Omitted | Custom proxy URL used to load the page. |
|
|
274
|
+
| `maxRetries` | `maxRetries` | number (integer) | Omitted | Maximum number of retries, as a nonnegative integer. Omit this parameter for no limit. |
|
|
275
|
+
| `saveResult` | `saveResult` | boolean | `false` | Whether to save the result to the dashboard Result tab. |
|
|
276
|
+
| `blockResources` | `blockResources` | boolean | `false` | Whether to block images, fonts, and stylesheets while loading the page. |
|
|
277
|
+
| `waitForSelector` | `waitForSelector` | string | Omitted | Wait for the page to contain the specified CSS selector before returning the result. |
|
|
278
|
+
| `returnCookie` | `returnCookie` | boolean | `false` | Whether to include browser session cookies in the response. |
|
|
279
|
+
| `screenshot` | `screenshot` | string: `full`, `top` | `"full"` | Screenshot area to capture: full for the entire page or top for the top viewport. |
|
|
280
|
+
| `html` | `html` | boolean | `true` | Whether to include the page HTML in the response. |
|
|
281
|
+
| `markdown` | `markdown` | boolean | `false` | Whether to include the page Markdown in the response. |
|
|
282
|
+
|
|
283
|
+
#### Example
|
|
284
|
+
|
|
285
|
+
```js
|
|
286
|
+
import { getScreenshot } from "@mrscraper/sdk";
|
|
287
|
+
|
|
288
|
+
const result = await getScreenshot("https://example.com", {
|
|
289
|
+
screenshot: "top",
|
|
290
|
+
html: false,
|
|
291
|
+
markdown: true,
|
|
129
292
|
});
|
|
130
293
|
console.log(result.data);
|
|
131
294
|
```
|
|
132
295
|
|
|
133
|
-
|
|
296
|
+
#### Response
|
|
134
297
|
|
|
135
|
-
|
|
298
|
+
The response body contains a base64 screenshot and requested page outputs. The API can still include HTML when HTML output is disabled.
|
|
136
299
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
300
|
+
**Success response**
|
|
301
|
+
|
|
302
|
+
```json
|
|
303
|
+
{
|
|
304
|
+
"status_code": 200,
|
|
305
|
+
"data": {
|
|
306
|
+
"html": "<html>...</html>",
|
|
307
|
+
"screenshot": "BASE64_PNG_DATA",
|
|
308
|
+
"markdown": "# Example page\n\n..."
|
|
309
|
+
},
|
|
310
|
+
"headers": {
|
|
311
|
+
"content-type": "application/json; charset=utf-8"
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Scrape brand
|
|
317
|
+
|
|
318
|
+
#### Description
|
|
319
|
+
|
|
320
|
+
Extract a website's colors, typography, logos, and social links as JSON.
|
|
140
321
|
|
|
141
|
-
|
|
142
|
-
console.log(created.data); // Read the job ID from the API response.
|
|
322
|
+
#### Parameters
|
|
143
323
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
324
|
+
| Parameter | HTTP field | Type | Default | Description |
|
|
325
|
+
| --------- | ---------- | ------ | -------- | -------------------------------------------------- |
|
|
326
|
+
| `url` | `url` | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
|
|
147
327
|
|
|
148
|
-
|
|
149
|
-
|
|
328
|
+
The HTTP deadline is fixed at 120 seconds. It is not a service parameter.
|
|
329
|
+
|
|
330
|
+
The request uses `action=brand-scraping` and `bundle=none`; page controls are not accepted.
|
|
331
|
+
|
|
332
|
+
#### Example
|
|
333
|
+
|
|
334
|
+
```js
|
|
335
|
+
import { scrapeBrand } from "@mrscraper/sdk";
|
|
336
|
+
|
|
337
|
+
const result = await scrapeBrand("https://example.com");
|
|
338
|
+
console.log(result.data);
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
#### Response
|
|
342
|
+
|
|
343
|
+
The API body contains message and a data object with job_id, status, url, final_url, brand, and error. Brand details are available at data.data.brand in the response envelope.
|
|
344
|
+
|
|
345
|
+
**Success response**
|
|
346
|
+
|
|
347
|
+
```json
|
|
348
|
+
{
|
|
349
|
+
"status_code": 200,
|
|
350
|
+
"data": {
|
|
351
|
+
"data": {
|
|
352
|
+
"job_id": "JOB_ID",
|
|
353
|
+
"status": "succeeded",
|
|
354
|
+
"url": "https://example.com",
|
|
355
|
+
"final_url": "https://example.com",
|
|
356
|
+
"brand": {
|
|
357
|
+
"name": "Example brand",
|
|
358
|
+
"colors": {
|
|
359
|
+
"background": "#ffffff",
|
|
360
|
+
"text": "#222222"
|
|
361
|
+
},
|
|
362
|
+
"typography": {
|
|
363
|
+
"body": {
|
|
364
|
+
"font_family": "Example font"
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
"error": null,
|
|
369
|
+
"bundle_url": null
|
|
370
|
+
},
|
|
371
|
+
"message": "Example response"
|
|
372
|
+
},
|
|
373
|
+
"headers": {
|
|
374
|
+
"content-type": "application/json"
|
|
375
|
+
}
|
|
376
|
+
}
|
|
150
377
|
```
|
|
151
378
|
|
|
152
|
-
|
|
379
|
+
### Scrape JSON
|
|
380
|
+
|
|
381
|
+
#### Description
|
|
382
|
+
|
|
383
|
+
Extract structured JSON from a page using a natural-language prompt. Append Json Schema: and a JSON schema to shape the output.
|
|
153
384
|
|
|
154
|
-
|
|
385
|
+
#### Parameters
|
|
155
386
|
|
|
156
|
-
|
|
387
|
+
| Parameter | HTTP field | Type | Default | Description |
|
|
388
|
+
| ------------------ | ------------------ | ------------------------------------------------------------------ | --------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
389
|
+
| `url` | `url` | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
|
|
390
|
+
| `timeout` | `timeout` | number (integer) | `300` | Page load timeout in seconds, from 1 to 300. The HTTP request allows 30 additional seconds. |
|
|
391
|
+
| `geoCode` | `geoCode` | string | `"us"` | Two-letter country code to load the page from, sent in lowercase. |
|
|
392
|
+
| `proxyCountry` | `proxyCountry` | string | `"us"` | Two-letter country code of the proxy server, sent in lowercase. |
|
|
393
|
+
| `super` | `super` | boolean | `false` | Whether to route the request through real devices. |
|
|
394
|
+
| `waitUntil` | `waitUntil` | string: `domcontentloaded`, `load`, `networkidle0`, `networkidle2` | `"domcontentloaded"` | Navigation completion event to wait for: domcontentloaded, load, networkidle0, or networkidle2. |
|
|
395
|
+
| `proxy` | `proxy` | string | Omitted | Custom proxy URL used to load the page. |
|
|
396
|
+
| `maxRetries` | `maxRetries` | number (integer) | Omitted | Maximum number of retries, as a nonnegative integer. Omit this parameter for no limit. |
|
|
397
|
+
| `saveResult` | `saveResult` | boolean | `false` | Whether to save the result to the dashboard Result tab. |
|
|
398
|
+
| `prompt` | `prompt` | string | `"Extract all data as complete as possible."` | Instructions describing the data to extract. Append Json Schema: and a JSON schema to shape the output. |
|
|
399
|
+
| `browserRendering` | `browserRendering` | boolean | `false` | Whether to render the page in a browser before returning the result. |
|
|
400
|
+
| `html` | `html` | boolean | `false` | Whether to include the page HTML in the response. |
|
|
401
|
+
| `screenshot` | `screenshot` | boolean | `false` | Whether to include a base64 screenshot in the response. |
|
|
157
402
|
|
|
158
|
-
|
|
159
|
-
import { web_search } from "@mrscraper/sdk";
|
|
403
|
+
The request uses `agent=general` and GET. If the encoded URL exceeds 8,000 characters, it switches to POST with `url`, `prompt`, and `agent` in the body; page controls remain in the query.
|
|
160
404
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
405
|
+
#### Example
|
|
406
|
+
|
|
407
|
+
```js
|
|
408
|
+
import { scrapeJson } from "@mrscraper/sdk";
|
|
409
|
+
|
|
410
|
+
const result = await scrapeJson("https://example.com", {
|
|
411
|
+
prompt:
|
|
412
|
+
'Extract the first 2 items with title and price. Json Schema: {"type":"array","items":{"type":"object","properties":{"title":{"type":"string"},"price":{"type":"string"}},"required":["title","price"]}}',
|
|
413
|
+
browserRendering: true,
|
|
167
414
|
});
|
|
168
415
|
console.log(result.data);
|
|
169
416
|
```
|
|
170
417
|
|
|
171
|
-
|
|
418
|
+
#### Response
|
|
419
|
+
|
|
420
|
+
Extraction results are in the API body's data field and follow the requested schema. Response metadata includes thread_id, token_usage, status, error, runtime, and cookies. html, markdown, and screenshot can be empty strings when not requested.
|
|
421
|
+
|
|
422
|
+
**Success response**
|
|
423
|
+
|
|
424
|
+
```json
|
|
425
|
+
{
|
|
426
|
+
"status_code": 200,
|
|
427
|
+
"data": {
|
|
428
|
+
"success": true,
|
|
429
|
+
"data": [
|
|
430
|
+
{
|
|
431
|
+
"title": "Example item",
|
|
432
|
+
"price": "10.00"
|
|
433
|
+
}
|
|
434
|
+
],
|
|
435
|
+
"thread_id": "THREAD_ID",
|
|
436
|
+
"token_usage": 1,
|
|
437
|
+
"html": "",
|
|
438
|
+
"markdown": "",
|
|
439
|
+
"screenshot": "",
|
|
440
|
+
"status": "Results ready",
|
|
441
|
+
"error": "",
|
|
442
|
+
"runtime": 1.23,
|
|
443
|
+
"cookies": []
|
|
444
|
+
},
|
|
445
|
+
"headers": {
|
|
446
|
+
"content-type": "application/json"
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
```
|
|
172
450
|
|
|
173
|
-
|
|
174
|
-
|--------|---------|-------------|
|
|
175
|
-
| `url` | Required first argument | The search query |
|
|
176
|
-
| `token` | Environment variable | API token override |
|
|
177
|
-
| `raw` | `true` | Request HTML when true |
|
|
178
|
-
| `format` | `"json"` | `"json"` or `"html"` when `raw` is false |
|
|
179
|
-
| `region`, `language` | unset | Country and language |
|
|
180
|
-
| `page` | unset | Results page number, starting at `1` |
|
|
181
|
-
| `render_js` | `false` | Render JavaScript features |
|
|
182
|
-
| `timeout` | `600` | HTTP request timeout in seconds |
|
|
451
|
+
### Web search
|
|
183
452
|
|
|
184
|
-
|
|
453
|
+
#### Description
|
|
185
454
|
|
|
186
|
-
|
|
187
|
-
import { account } from "@mrscraper/sdk";
|
|
455
|
+
Search the web and return ranked results with titles, URLs, descriptions, and sources.
|
|
188
456
|
|
|
189
|
-
|
|
190
|
-
console.log(result.data.subscription_status);
|
|
191
|
-
console.log(result.data.token_remaining);
|
|
192
|
-
console.log(result.data.user.email);
|
|
193
|
-
```
|
|
457
|
+
#### Parameters
|
|
194
458
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
`
|
|
200
|
-
API keys, billing identifiers, and sensitive response headers are excluded.
|
|
459
|
+
| Parameter | HTTP field | Type | Default | Description |
|
|
460
|
+
| ------------ | ------------ | ---------------- | -------- | ------------------------------------------------------------------------------------------------- |
|
|
461
|
+
| `query` | `query` | string | Required | Search query text, trimmed before sending, containing 1 to 1000 characters. |
|
|
462
|
+
| `country` | `country` | string | `"us"` | Two-letter country code to search from, sent in lowercase. |
|
|
463
|
+
| `numResults` | `numResults` | number (integer) | `10` | Number of search results to request, as an integer from 10 to 100. Fewer results may be returned. |
|
|
201
464
|
|
|
202
|
-
|
|
465
|
+
The HTTP deadline is fixed at 120 seconds. It is not a service parameter.
|
|
203
466
|
|
|
204
|
-
|
|
467
|
+
#### Example
|
|
205
468
|
|
|
206
|
-
```
|
|
207
|
-
import {
|
|
208
|
-
import type { ScraperOptions, ScraperSitemapOptions, MrScraperResponse } from "@mrscraper/sdk";
|
|
469
|
+
```js
|
|
470
|
+
import { webSearch } from "@mrscraper/sdk";
|
|
209
471
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
472
|
+
const result = await webSearch("site:example.com documentation", {
|
|
473
|
+
country: "id",
|
|
474
|
+
numResults: 20,
|
|
475
|
+
});
|
|
476
|
+
console.log(result.data);
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
#### Response
|
|
480
|
+
|
|
481
|
+
The API body contains success, message, a data array, and tokenUsage. Each result includes rank, title, url, description, and source.
|
|
482
|
+
|
|
483
|
+
**Success response**
|
|
484
|
+
|
|
485
|
+
```json
|
|
486
|
+
{
|
|
487
|
+
"status_code": 200,
|
|
488
|
+
"data": {
|
|
489
|
+
"success": true,
|
|
490
|
+
"message": "Example response",
|
|
491
|
+
"data": [
|
|
492
|
+
{
|
|
493
|
+
"rank": 1,
|
|
494
|
+
"title": "Example result",
|
|
495
|
+
"url": "https://example.com",
|
|
496
|
+
"description": "Example result description.",
|
|
497
|
+
"source": "example.com"
|
|
498
|
+
}
|
|
499
|
+
],
|
|
500
|
+
"tokenUsage": 1
|
|
501
|
+
},
|
|
502
|
+
"headers": {
|
|
503
|
+
"content-type": "application/json; charset=utf-8"
|
|
218
504
|
}
|
|
219
505
|
}
|
|
220
506
|
```
|
|
221
507
|
|
|
222
|
-
##
|
|
508
|
+
## Response format
|
|
223
509
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
510
|
+
Successful services use an envelope containing `status_code`, `data`, and `headers`. The `data` field contains the API response body; its field names are not converted to the SDK's naming style. Status preserves the complete body without adding summary fields.
|
|
511
|
+
|
|
512
|
+
```json
|
|
513
|
+
{
|
|
514
|
+
"status_code": 200,
|
|
515
|
+
"data": "<html><body>Example page content...</body></html>",
|
|
516
|
+
"headers": {
|
|
517
|
+
"content-type": "text/html; charset=utf-8"
|
|
518
|
+
}
|
|
519
|
+
}
|
|
228
520
|
```
|
|
229
521
|
|
|
230
|
-
|
|
522
|
+
Responses are `MrScraperResponse<T>` objects. JSON becomes JavaScript values, text remains `string`, and binary remains `Buffer`. Sensitive response headers are removed for status.
|
|
231
523
|
|
|
232
|
-
##
|
|
524
|
+
## Error handling
|
|
233
525
|
|
|
234
|
-
|
|
526
|
+
Authentication, HTTP, network, and timeout failures throw `MrScraperError`. Its `status` property is the HTTP status when available. Invalid arguments throw `TypeError` or `RangeError` before the request.
|
|
235
527
|
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
|
|
528
|
+
```js
|
|
529
|
+
import { scrapeHtml, MrScraperError } from "@mrscraper/sdk";
|
|
530
|
+
|
|
531
|
+
try {
|
|
532
|
+
await scrapeHtml("https://example.com");
|
|
533
|
+
} catch (error) {
|
|
534
|
+
if (error instanceof MrScraperError)
|
|
535
|
+
console.error(error.status, error.message);
|
|
536
|
+
else throw error;
|
|
537
|
+
}
|
|
239
538
|
```
|
|
240
539
|
|
|
241
|
-
|
|
540
|
+
## Integration features
|
|
242
541
|
|
|
243
|
-
|
|
244
|
-
node --input-type=module <<'NODE'
|
|
245
|
-
import { account } from "./dist/index.js";
|
|
542
|
+
### Configuration
|
|
246
543
|
|
|
247
|
-
|
|
248
|
-
console.log(result.status_code, result.data);
|
|
249
|
-
NODE
|
|
250
|
-
```
|
|
544
|
+
Functions return promises and use camelCase options. Omit optional controls or use `undefined`; explicit `false` and `0` are preserved. TypeScript exports include `PageOptions`, `HtmlOptions`, `MarkdownOptions`, `ScreenshotOptions`, `JsonOptions`, `WebSearchOptions`, `StatusOptions`, and `MrScraperResponse<T>`.
|
|
251
545
|
|
|
252
|
-
|
|
546
|
+
### Advanced usage
|
|
253
547
|
|
|
254
|
-
|
|
255
|
-
node --input-type=module <<'NODE'
|
|
256
|
-
import { scraper_markdown } from "./dist/index.js";
|
|
548
|
+
Supply a generic response body type when you know the returned API shape:
|
|
257
549
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
550
|
+
```ts
|
|
551
|
+
import { scrapeJson } from "@mrscraper/sdk";
|
|
552
|
+
const result = await scrapeJson<{ data: { title: string } }>(
|
|
553
|
+
"https://example.com",
|
|
554
|
+
{ prompt: "Extract the page title" },
|
|
555
|
+
);
|
|
556
|
+
console.log(result.data.data.title);
|
|
261
557
|
```
|
|
262
558
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
```bash
|
|
266
|
-
node --input-type=module <<'NODE'
|
|
267
|
-
import { scrape_brand } from "./dist/index.js";
|
|
559
|
+
Save screenshot JSON as an image when the API returns a base64 screenshot:
|
|
268
560
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
561
|
+
```js
|
|
562
|
+
import { getScreenshot } from "@mrscraper/sdk";
|
|
563
|
+
import { writeFile } from "node:fs/promises";
|
|
564
|
+
const result = await getScreenshot("https://example.com");
|
|
565
|
+
if (
|
|
566
|
+
typeof result.data === "object" &&
|
|
567
|
+
typeof result.data?.screenshot === "string"
|
|
568
|
+
) {
|
|
569
|
+
await writeFile("page.png", Buffer.from(result.data.screenshot, "base64"));
|
|
570
|
+
}
|
|
272
571
|
```
|
|
273
572
|
|
|
274
|
-
|
|
573
|
+
### Troubleshooting
|
|
574
|
+
|
|
575
|
+
Check environment credentials when authentication fails. Use camelCase option names and `super`, rather than old snake_case options or `superMode`. Page timeouts are integers from 1 to 300; status and search do not expose timeout options.
|
|
576
|
+
|
|
577
|
+
## Migration
|
|
275
578
|
|
|
276
|
-
|
|
579
|
+
Replace `account()` with `status()` and read the raw API body. Remove status/search timeout options and rename `superMode` to `super`. Replace combined scraper calls with `scrapeHtml`, `scrapeMarkdown`, or `getScreenshot`; use camelCase options. Replace `full_page` with `screenshot: "full"` or `"top"`. Search uses `query`, `country`, and `numResults`.
|
|
277
580
|
|
|
278
|
-
|
|
279
|
-
|
|
581
|
+
## Development and testing
|
|
582
|
+
|
|
583
|
+
### Automated checks
|
|
584
|
+
|
|
585
|
+
The automated suite checks service behavior without production API calls.
|
|
280
586
|
|
|
281
587
|
```bash
|
|
282
588
|
npm ci
|
|
283
589
|
npm test
|
|
284
|
-
npm
|
|
285
|
-
npm publish --dry-run --access public
|
|
590
|
+
npm run build
|
|
286
591
|
```
|
|
287
592
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
593
|
+
### Manual checks
|
|
594
|
+
|
|
595
|
+
The following commands call the live API using your credentials and consume quota.
|
|
291
596
|
|
|
292
597
|
```bash
|
|
293
|
-
npm
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
npm view @mrscraper/sdk dist-tags --json
|
|
598
|
+
npm run build
|
|
599
|
+
node file.js status
|
|
600
|
+
node file.js scrapeHtml https://example.com
|
|
601
|
+
node file.js webSearch "site:example.com documentation"
|
|
298
602
|
```
|
|
299
603
|
|
|
300
|
-
Complete npm's browser login and two-factor authentication prompts. The
|
|
301
|
-
`prepublishOnly` script rebuilds `dist` before publishing. Each version can be
|
|
302
|
-
published only once. For later releases, update `package.json` and
|
|
303
|
-
`package-lock.json` together with a new version before validating and publishing.
|
|
304
|
-
|
|
305
604
|
## License
|
|
306
605
|
|
|
307
|
-
MIT
|
|
606
|
+
MIT. See [LICENSE](./LICENSE).
|