scraply 1.0.19 → 1.0.20

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "scraply",
3
3
  "description": "A simple, configurable and functional content scraper",
4
- "version": "1.0.19",
4
+ "version": "1.0.20",
5
5
  "main": "src/scraply.js",
6
6
  "type": "module",
7
7
  "scripts": {
package/readme.md CHANGED
@@ -70,15 +70,16 @@ CRAWLER: {
70
70
  'aside',
71
71
  'button'
72
72
  ],
73
- RETRY_STATUS_CODES: [408, 429, 500, 502, 503, 504],
74
- REQUEST_TIMEOUT: 4000,
75
- MAX_REDIRECTS: 3,
76
- MAX_RETRIES: 2,
73
+ RETRY_STATUS_CODES: [408, 500, 502, 503, 504],
74
+ REQUEST_TIMEOUT: 3000,
75
+ MAX_REDIRECTS: 2,
76
+ MAX_CONTENT_LENGTH: 20 * 1024 * 1024, // 20MB
77
+ MAX_RETRIES: 1,
77
78
  CRAWL_DELAY_MS: 200,
78
- CRAWL_ERROR_RETRY_DELAY_MS: 800,
79
+ CRAWL_ERROR_RETRY_DELAY_MS: 1000,
79
80
  CRAWL_RATE_LIMIT_FALLBACK_DELAY_MS: 60000,
80
- EXIT_CODE_RATE_LIMIT: 10,
81
- EXIT_ON_RATE_LIMIT: true
81
+ EXIT_ON_RATE_LIMIT: true, // If true, forces exit instantly. If false, only exits after retries (if still 429)
82
+ EXIT_CODE_RATE_LIMIT: 10
82
83
  },
83
84
 
84
85
  DATA_FORMATTER: {
@@ -35,14 +35,15 @@ export const DEFAULT_CONFIG = {
35
35
  'aside',
36
36
  'button'
37
37
  ],
38
- RETRY_STATUS_CODES: [408, 429, 500, 502, 503, 504],
39
- REQUEST_TIMEOUT: 4000,
40
- MAX_REDIRECTS: 3,
41
- MAX_RETRIES: 2,
38
+ RETRY_STATUS_CODES: [408, 500, 502, 503, 504],
39
+ REQUEST_TIMEOUT: 3000,
40
+ MAX_REDIRECTS: 2,
41
+ MAX_CONTENT_LENGTH: 20 * 1024 * 1024, // 20MB
42
+ MAX_RETRIES: 1,
42
43
  CRAWL_DELAY_MS: 200,
43
- CRAWL_ERROR_RETRY_DELAY_MS: 800,
44
+ CRAWL_ERROR_RETRY_DELAY_MS: 1000,
44
45
  CRAWL_RATE_LIMIT_FALLBACK_DELAY_MS: 60000,
45
- EXIT_ON_RATE_LIMIT: true,
46
+ EXIT_ON_RATE_LIMIT: true, // If true, forces exit instantly. If false, only exits after retries (if still 429)
46
47
  EXIT_CODE_RATE_LIMIT: 10
47
48
  },
48
49
 
@@ -6,17 +6,20 @@ export async function fetchURL(url, retries = 2) {
6
6
  try {
7
7
  const response = await axios.get(url, {
8
8
  timeout: CONFIG.CRAWLER.REQUEST_TIMEOUT,
9
- maxRedirects: CONFIG.CRAWLER.MAX_REDIRECTS
9
+ maxRedirects: CONFIG.CRAWLER.MAX_REDIRECTS,
10
+ maxContentLength: CONFIG.CRAWLER.MAX_CONTENT_LENGTH
10
11
  });
11
12
 
12
13
  const { 'content-type': contentType } = response.headers;
13
14
 
15
+ if (!contentType) {
16
+ console.log(`Missing Content-Type header for ${url}`);
17
+ return { error: `Missing Content-Type header`, status: response.status };
18
+ };
19
+
14
20
  // Validate content type
15
21
  if (!CONFIG.CRAWLER.ALLOWED_CONTENT_TYPES.some(type => contentType.includes(type))) {
16
- return {
17
- error: `Content-Type ${contentType} is not allowed.`,
18
- status: response.status
19
- };
22
+ return { error: `Content-Type ${contentType} is not allowed.`, status: response.status };
20
23
  };
21
24
 
22
25
  return { data: response.data, status: response.status };
@@ -32,7 +35,7 @@ export async function fetchURL(url, retries = 2) {
32
35
 
33
36
  // If still 429 after retries, exit with configured code
34
37
  if (error.response?.status === 429) {
35
- console.log(`Force exiting with code ${CONFIG.CRAWLER.EXIT_CODE_RATE_LIMIT} after retries...`);
38
+ console.log(`Force exiting with code ${CONFIG.CRAWLER.EXIT_CODE_RATE_LIMIT} (after retries)...`);
36
39
  process.exit(CONFIG.CRAWLER.EXIT_CODE_RATE_LIMIT);
37
40
  }
38
41