@crawlee/linkedom 4.0.0-beta.120 → 4.0.0-beta.121

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.
@@ -1,6 +1,6 @@
1
1
  import type { BasicCrawlingContext, CrawlingContext, EnqueueLinksOptions, ErrorHandler, GetUserDataFromRequest, HttpCrawlerOptions, InternalHttpCrawlingContext, InternalHttpHook, IRequestManager, RequestHandler, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas, SkippedRequestCallback } from '@crawlee/http';
2
2
  import { HttpCrawler } from '@crawlee/http';
3
- import type { Dictionary } from '@crawlee/types';
3
+ import type { BatchAddRequestsResult, Dictionary } from '@crawlee/types';
4
4
  import { type CheerioRoot } from '@crawlee/utils/internal';
5
5
  import { type RobotsTxtFile } from '@crawlee/utils';
6
6
  import * as cheerio from 'cheerio';
@@ -46,6 +46,10 @@ JSONData extends Dictionary = any> extends InternalHttpCrawlingContext<UserData,
46
46
  * ```
47
47
  */
48
48
  parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioRoot>;
49
+ /**
50
+ * Helper function for extracting URLs from the parsed HTML and adding them to the request queue.
51
+ */
52
+ enqueueLinks(options?: LinkeDOMCrawlerEnqueueLinksOptions): Promise<BatchAddRequestsResult>;
49
53
  }
50
54
  export type LinkeDOMRequestHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
51
55
  JSONData extends Dictionary = any> = RequestHandler<LinkeDOMCrawlingContext<UserData, JSONData>>;
@@ -123,14 +127,14 @@ JSONData extends Dictionary = any> = RequestHandler<LinkeDOMCrawlingContext<User
123
127
  */
124
128
  export declare class LinkeDOMCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends LinkeDOMCrawlingContext = LinkeDOMCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<LinkeDOMCrawlingContext['request']>>> extends HttpCrawler<LinkeDOMCrawlingContext, ContextExtension, ExtendedContext, Routes> {
125
129
  #private;
126
- constructor(options: LinkeDOMCrawlerOptions<ContextExtension, ExtendedContext, any, any, Routes>);
130
+ constructor(options?: LinkeDOMCrawlerOptions<ContextExtension, ExtendedContext, any, any, Routes>);
127
131
  // @ts-ignore optional peer dependency or compatibility with es2022
128
132
  protected buildContextPipeline(): import("@crawlee/http").ContextPipeline<CrawlingContext<Dictionary>, InternalHttpCrawlingContext<any, any> & {
129
133
  readonly window: Window;
130
134
  readonly body: string;
131
135
  readonly document: Document;
132
136
  } & {
133
- enqueueLinks: (enqueueOptions?: LinkeDOMCrawlerEnqueueLinksOptions) => Promise<unknown>;
137
+ enqueueLinks: (enqueueOptions?: LinkeDOMCrawlerEnqueueLinksOptions) => Promise<BatchAddRequestsResult>;
134
138
  waitForSelector(selector: string, timeoutMs?: number): Promise<void>;
135
139
  parseWithCheerio(selector?: string, _timeoutMs?: number): Promise<cheerio.CheerioAPI>;
136
140
  }>;
@@ -76,7 +76,7 @@ import { DOMParser } from 'linkedom/cached';
76
76
  */
77
77
  export class LinkeDOMCrawler extends HttpCrawler {
78
78
  static #parser = new DOMParser();
79
- constructor(options) {
79
+ constructor(options = {}) {
80
80
  const { contextPipelineBuilder, ...rest } = options;
81
81
  super({
82
82
  ...rest,
@@ -126,18 +126,18 @@ export class LinkeDOMCrawler extends HttpCrawler {
126
126
  async addHelpers(crawlingContext) {
127
127
  return {
128
128
  enqueueLinks: async (enqueueOptions) => {
129
- return linkedomCrawlerEnqueueLinks({
129
+ return (await linkedomCrawlerEnqueueLinks({
130
130
  options: {
131
131
  ...enqueueOptions,
132
132
  limit: await this.calculateEnqueuedRequestLimit(enqueueOptions?.limit),
133
133
  },
134
- window: document.defaultView,
134
+ window: crawlingContext.window,
135
135
  requestManager: await this.getRequestManager(),
136
136
  robotsTxtFile: await this.getRobotsTxtFileForUrl(crawlingContext.request.url),
137
137
  onSkippedRequest: this.handleSkippedRequest,
138
138
  originalRequestUrl: crawlingContext.request.url,
139
139
  finalRequestUrl: crawlingContext.request.loadedUrl,
140
- });
140
+ })); // TODO make this type safe, see https://github.com/apify/crawlee/issues/4024
141
141
  },
142
142
  async waitForSelector(selector, timeoutMs = 5_000) {
143
143
  const $ = cheerio.load(crawlingContext.body);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/linkedom",
3
- "version": "4.0.0-beta.120",
3
+ "version": "4.0.0-beta.121",
4
4
  "description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -49,9 +49,9 @@
49
49
  "dependencies": {
50
50
  "@apify/timeout": "^0.4.4",
51
51
  "@apify/utilities": "^2.15.5",
52
- "@crawlee/http": "4.0.0-beta.120",
53
- "@crawlee/types": "4.0.0-beta.120",
54
- "@crawlee/utils": "4.0.0-beta.120",
52
+ "@crawlee/http": "4.0.0-beta.121",
53
+ "@crawlee/types": "4.0.0-beta.121",
54
+ "@crawlee/utils": "4.0.0-beta.121",
55
55
  "cheerio": "^1.0.0",
56
56
  "linkedom": "^0.18.10",
57
57
  "ow": "^2.0.0",
@@ -64,5 +64,5 @@
64
64
  }
65
65
  }
66
66
  },
67
- "gitHead": "da5d427c4c1c9dcaea95b151e9c4c7310100885d"
67
+ "gitHead": "5027317de626f5ba6de5047ae9341a898258cc5a"
68
68
  }