scraply 1.0.16 → 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: {
|
package/src/loadConfig.js
CHANGED
|
@@ -19,17 +19,11 @@ export function loadConfig(userConfig = {}) {
|
|
|
19
19
|
config.CRAWLER.QUEUE_PATH = path.posix.join(config.MAIN_DIR, 'queue.json');
|
|
20
20
|
config.CRAWLER.CRAWLED_PATH = path.posix.join(config.MAIN_DIR, 'crawled');
|
|
21
21
|
config.DATA_FORMATTER.FORMATTED_PATH = path.posix.join(config.MAIN_DIR, 'formatted');
|
|
22
|
-
config.DATA_FORMATTER.ERROR_REPORT_PATH = path.posix.join(config.MAIN_DIR, 'error-report.json');
|
|
23
22
|
|
|
24
23
|
// If INCLUDE_URLS is not specified, set it to INITIAL_URLS by default
|
|
25
24
|
if (!config.CRAWLER.INCLUDE_URLS || config.CRAWLER.INCLUDE_URLS.length === 0) {
|
|
26
25
|
config.CRAWLER.INCLUDE_URLS = config.CRAWLER.INITIAL_URLS.map(url => `${url}.*`);
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
// If HARD_CODED_LINKS is missing, set to an empty array by default
|
|
30
|
-
if (!config.DATA_FORMATTER.HARD_CODED_LINKS) {
|
|
31
|
-
config.DATA_FORMATTER.HARD_CODED_LINKS = [];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
28
|
return config;
|
|
35
29
|
};
|
|
@@ -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;
|