@crawlee/utils 4.0.0-beta.211 → 4.0.0-beta.212
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/internals/robots.d.ts +0 -1
- package/internals/robots.js +2 -2
- package/internals/sitemap.d.ts +1 -1
- package/internals/sitemap.js +14 -14
- package/package.json +4 -4
package/internals/robots.d.ts
CHANGED
|
@@ -53,7 +53,6 @@ export declare class RobotsTxtFile {
|
|
|
53
53
|
* @param [proxyUrl] a proxy to be used for fetching the robots.txt file
|
|
54
54
|
*/
|
|
55
55
|
static from(url: string, content: string, proxyUrl?: string): RobotsTxtFile;
|
|
56
|
-
private static load;
|
|
57
56
|
/**
|
|
58
57
|
* Get crawl delay for a given user agent.
|
|
59
58
|
* @param [userAgent] relevant user agent, default to `*`
|
package/internals/robots.js
CHANGED
|
@@ -43,7 +43,7 @@ export class RobotsTxtFile {
|
|
|
43
43
|
const robotsTxtFileUrl = new URL(url);
|
|
44
44
|
robotsTxtFileUrl.pathname = '/robots.txt';
|
|
45
45
|
robotsTxtFileUrl.search = '';
|
|
46
|
-
return RobotsTxtFile
|
|
46
|
+
return RobotsTxtFile.#load(robotsTxtFileUrl.toString(), options);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Allows providing the URL and robots.txt content explicitly instead of loading it from the target site.
|
|
@@ -55,7 +55,7 @@ export class RobotsTxtFile {
|
|
|
55
55
|
// @ts-ignore
|
|
56
56
|
return new RobotsTxtFile(url, robotsParser(url, content), proxyUrl);
|
|
57
57
|
}
|
|
58
|
-
static async load(url, options) {
|
|
58
|
+
static async #load(url, options) {
|
|
59
59
|
const { proxyUrl, logger, httpClient = new FetchHttpClient() } = options || {};
|
|
60
60
|
const response = await httpClient.sendRequest(new Request(url, { method: 'GET' }), {
|
|
61
61
|
proxyUrl,
|
package/internals/sitemap.d.ts
CHANGED
|
@@ -82,6 +82,7 @@ export declare function parseSitemap<T extends ParseSitemapOptions>(initialSourc
|
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
84
84
|
export declare class Sitemap {
|
|
85
|
+
#private;
|
|
85
86
|
readonly urls: string[];
|
|
86
87
|
constructor(urls: string[]);
|
|
87
88
|
/**
|
|
@@ -103,7 +104,6 @@ export declare class Sitemap {
|
|
|
103
104
|
* @param proxyUrl URL of a proxy to be used for fetching sitemap contents
|
|
104
105
|
*/
|
|
105
106
|
static fromXmlString(content: string, proxyUrl?: string, parseSitemapOptions?: ParseSitemapOptions): Promise<Sitemap>;
|
|
106
|
-
private static parse;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Given a list of URLs, discover related sitemap files for these domains by checking the `robots.txt` file,
|
package/internals/sitemap.js
CHANGED
|
@@ -14,16 +14,16 @@ class SitemapTxtParser extends Transform {
|
|
|
14
14
|
super({
|
|
15
15
|
readableObjectMode: true,
|
|
16
16
|
transform: (chunk, _encoding, callback) => {
|
|
17
|
-
this
|
|
17
|
+
this.#processBuffer(this.#decoder.write(chunk), false);
|
|
18
18
|
callback();
|
|
19
19
|
},
|
|
20
20
|
flush: (callback) => {
|
|
21
|
-
this
|
|
21
|
+
this.#processBuffer(this.#decoder.end(), true);
|
|
22
22
|
callback();
|
|
23
23
|
},
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
processBuffer(input, finalize) {
|
|
26
|
+
#processBuffer(input, finalize) {
|
|
27
27
|
this.#buffer += input;
|
|
28
28
|
if (finalize || this.#buffer.includes('\n')) {
|
|
29
29
|
const parts = this.#buffer
|
|
@@ -52,7 +52,7 @@ class SitemapXmlParser extends Transform {
|
|
|
52
52
|
#currentTag = undefined;
|
|
53
53
|
#url = {};
|
|
54
54
|
static async create() {
|
|
55
|
-
const { SAXParser } = await import('sax');
|
|
55
|
+
const { SAXParser } = (await import('sax')).default;
|
|
56
56
|
return new SitemapXmlParser(new SAXParser(true));
|
|
57
57
|
}
|
|
58
58
|
constructor(parser) {
|
|
@@ -72,13 +72,13 @@ class SitemapXmlParser extends Transform {
|
|
|
72
72
|
},
|
|
73
73
|
});
|
|
74
74
|
this.#parser = parser;
|
|
75
|
-
this.#parser.onopentag = this
|
|
76
|
-
this.#parser.onclosetag = this
|
|
77
|
-
this.#parser.ontext = this
|
|
78
|
-
this.#parser.oncdata = this
|
|
75
|
+
this.#parser.onopentag = this.#onOpenTag.bind(this);
|
|
76
|
+
this.#parser.onclosetag = this.#onCloseTag.bind(this);
|
|
77
|
+
this.#parser.ontext = this.#onText.bind(this);
|
|
78
|
+
this.#parser.oncdata = this.#onText.bind(this);
|
|
79
79
|
this.#parser.onerror = this.destroy.bind(this);
|
|
80
80
|
}
|
|
81
|
-
onOpenTag(node) {
|
|
81
|
+
#onOpenTag(node) {
|
|
82
82
|
if (this.#rootTagName !== undefined) {
|
|
83
83
|
if (node.name === 'loc' ||
|
|
84
84
|
node.name === 'lastmod' ||
|
|
@@ -94,7 +94,7 @@ class SitemapXmlParser extends Transform {
|
|
|
94
94
|
this.#rootTagName = 'sitemapindex';
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
onCloseTag(name) {
|
|
97
|
+
#onCloseTag(name) {
|
|
98
98
|
if (name === 'loc' || name === 'lastmod' || name === 'priority' || name === 'changefreq') {
|
|
99
99
|
this.#currentTag = undefined;
|
|
100
100
|
}
|
|
@@ -105,7 +105,7 @@ class SitemapXmlParser extends Transform {
|
|
|
105
105
|
this.#url = {};
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
onText(text) {
|
|
108
|
+
#onText(text) {
|
|
109
109
|
if (this.#currentTag === 'loc') {
|
|
110
110
|
if (this.#rootTagName === 'sitemapindex') {
|
|
111
111
|
this.push({ type: 'sitemapUrl', url: text.trim() });
|
|
@@ -323,7 +323,7 @@ export class Sitemap {
|
|
|
323
323
|
* @param proxyUrl URL of a proxy to be used for fetching sitemap contents
|
|
324
324
|
*/
|
|
325
325
|
static async load(urls, proxyUrl, parseSitemapOptions) {
|
|
326
|
-
return await this
|
|
326
|
+
return await this.#parse((Array.isArray(urls) ? urls : [urls]).map((url) => ({ type: 'url', url })), proxyUrl, parseSitemapOptions);
|
|
327
327
|
}
|
|
328
328
|
/**
|
|
329
329
|
* Parse XML sitemap content from a string and return URLs of referenced pages. If the sitemap references other sitemaps, they will be loaded via HTTP.
|
|
@@ -331,9 +331,9 @@ export class Sitemap {
|
|
|
331
331
|
* @param proxyUrl URL of a proxy to be used for fetching sitemap contents
|
|
332
332
|
*/
|
|
333
333
|
static async fromXmlString(content, proxyUrl, parseSitemapOptions) {
|
|
334
|
-
return await this
|
|
334
|
+
return await this.#parse([{ type: 'raw', content }], proxyUrl, parseSitemapOptions);
|
|
335
335
|
}
|
|
336
|
-
static async parse(sources, proxyUrl, parseSitemapOptions) {
|
|
336
|
+
static async #parse(sources, proxyUrl, parseSitemapOptions) {
|
|
337
337
|
const urls = [];
|
|
338
338
|
try {
|
|
339
339
|
for await (const item of parseSitemap(sources, proxyUrl, parseSitemapOptions)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/utils",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.212",
|
|
4
4
|
"description": "A set of shared utilities that can be used by crawlers",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.0.0"
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@apify/ps-tree": "^1.2.0",
|
|
46
46
|
"@apify/validations": "^1.1.0",
|
|
47
|
-
"@crawlee/http-client": "4.0.0-beta.
|
|
48
|
-
"@crawlee/types": "4.0.0-beta.
|
|
47
|
+
"@crawlee/http-client": "4.0.0-beta.212",
|
|
48
|
+
"@crawlee/types": "4.0.0-beta.212",
|
|
49
49
|
"@types/sax": "^1.2.7",
|
|
50
50
|
"cheerio": "^1.0.0",
|
|
51
51
|
"domhandler": "^5.0.3",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "171a63a5d7f2a6d74cbce58479204ac20d30b87e"
|
|
68
68
|
}
|