scraply 1.0.17 → 1.0.18
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
package/src/defaultConfig.js
CHANGED
|
@@ -42,8 +42,8 @@ export const DEFAULT_CONFIG = {
|
|
|
42
42
|
CRAWL_DELAY_MS: 200,
|
|
43
43
|
CRAWL_ERROR_RETRY_DELAY_MS: 800,
|
|
44
44
|
CRAWL_RATE_LIMIT_FALLBACK_DELAY_MS: 60000,
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
EXIT_ON_RATE_LIMIT: true,
|
|
46
|
+
EXIT_CODE_RATE_LIMIT: 10
|
|
47
47
|
},
|
|
48
48
|
|
|
49
49
|
DATA_FORMATTER: {
|
|
@@ -6,9 +6,6 @@ export const cleanHTML = ($) => {
|
|
|
6
6
|
$aux(CONFIG.CRAWLER.DOM_ELEMENTS_REMOVE.join(',')).remove();
|
|
7
7
|
$aux('*').contents().filter((_, el) => el.type === 'comment').remove();
|
|
8
8
|
|
|
9
|
-
// Get the text content of the body and decode HTML entities
|
|
10
|
-
// let bodyText = he.decode($aux('body').text(), { level: 'all' });
|
|
11
|
-
|
|
12
9
|
// Get the text content of the body element, ensuring spaces between child elements
|
|
13
10
|
let bodyText = getTextWithSpaces($aux, $aux('body'));
|
|
14
11
|
|
|
@@ -19,7 +19,7 @@ export const shouldRetry = async (error) => {
|
|
|
19
19
|
: parseInt(retryAfter, 10); // Seconds
|
|
20
20
|
console.log(`Rate limited. Retrying after ${waitTime} seconds...`);
|
|
21
21
|
} else if (rateLimitReset) {
|
|
22
|
-
waitTime = Math.max(parseInt(rateLimitReset, 10) - Math.
|
|
22
|
+
waitTime = Math.max(parseInt(rateLimitReset, 10) - Math.floor(Date.now() / 1000), 0);
|
|
23
23
|
console.log(`Rate limited. Retrying after ${waitTime} seconds...`);
|
|
24
24
|
} else {
|
|
25
25
|
waitTime = CONFIG.CRAWLER.CRAWL_RATE_LIMIT_FALLBACK_DELAY_MS / 1000;
|
|
@@ -7,7 +7,7 @@ import { saveDataset, saveQueue } from '../fileOperations.js';
|
|
|
7
7
|
|
|
8
8
|
export const processURL = async (entry, fileNumber, urlData) => {
|
|
9
9
|
const startTime = new Date().getTime();
|
|
10
|
-
const { url,
|
|
10
|
+
const { url, depth } = entry;
|
|
11
11
|
|
|
12
12
|
if (entry.file || (entry.error && !(await shouldRetry({ response: { status: entry.status } })))) return;
|
|
13
13
|
|
|
@@ -21,7 +21,7 @@ export const processURL = async (entry, fileNumber, urlData) => {
|
|
|
21
21
|
enqueueURLs(urlData, $, url, depth + 1);
|
|
22
22
|
|
|
23
23
|
const content = cleanHTML($);
|
|
24
|
-
const filename = saveDataset({ url,
|
|
24
|
+
const filename = saveDataset({ url, content }, fileNumber);
|
|
25
25
|
|
|
26
26
|
entry.file = filename;
|
|
27
27
|
entry.status = status;
|