SitemapRequestLoader
Implements
Index
Methods
[asyncIterator]
Can be used to iterate over the loader instance in a
for await .. ofloop. Provides an alternative for the repeated use offetchNextRequest.Returns AsyncGenerator<CrawleeRequest<Dictionary>, void, unknown>
checkReadiness
Reports whether the loader has a request to hand over, is waiting on one, or is done — see RequestSourceStatus.
A consumer's task loop is gated on this, so implementations MUST answer
readybefore evaluating anything else.finishedmay arrive late behind distributed storage, but it is never wrong.Returns Promise<RequestLoaderStatus>
fetchNextRequest
Gets the next Request to process, or
nullif there are no more pending requests.The returned request is marked as in progress and remains so until it is passed to IRequestLoader.markRequestAsHandled. The caller is responsible for eventually marking every fetched request as handled; otherwise the loader never considers itself finished and the request may be re-served after a restart. See the request lifecycle contract on IRequestLoader.
Returns Promise<null | CrawleeRequest<Dictionary>>
getHandledCount
Returns the number of requests in the loader that have been handled.
Returns Promise<number>
getPendingCount
Returns an approximation of the number of pending requests in the loader.
Returns Promise<number>
getTotalCount
Returns an approximation of the total number of requests in the loader (i.e. pending + handled).
Returns Promise<number>
isSitemapFullyLoaded
Indicates whether the background processing of sitemap contents has successfully finished.
If this is
false, the background processing is either still in progress or was aborted.Returns boolean
markRequestAsHandled
Marks a request previously returned by IRequestLoader.fetchNextRequest as handled, removing it from the set of in-progress requests.
Call this once you are done with the request — whether processing succeeded or was abandoned after exhausting retries. Because a loader cannot take a request back, marking it handled is the only way to signal completion; failing to do so prevents IRequestLoader.checkReadiness from ever reporting
finishedand skews the handled and pending counts. See the request lifecycle contract on IRequestLoader.Parameters
request: CrawleeRequest<Dictionary>
Returns Promise<void>
persistState
Persists the current state of the loader into the default KeyValueStore.
Not all loaders support persistence; implementations that do not should leave this
undefined.Returns Promise<void>
teardown
Aborts the internal sitemap loading, stops the processing of the sitemap contents and drops all the pending URLs.
Calling
fetchNextRequest()after this method will always returnnull.Returns Promise<void>
toTandem
Combines this list with a request manager (a RequestQueue by default) into a RequestManagerTandem, allowing requests to be added and reclaimed while still being read from this list first.
Parameters
optionalrequestManager: IRequestManager
Returns Promise<IRequestManager>
staticopen
Open a sitemap and start processing it.
Resolves to a new instance of
SitemapRequestLoader, which might not be fully loaded yet - i.e. the sitemap might still be loading in the background.Track the loading progress using the
isSitemapFullyLoadedproperty.Parameters
options: SitemapRequestLoaderOptions
Returns Promise<SitemapRequestLoader>
A list of URLs to crawl parsed from a sitemap.
The loading of the sitemap is performed in the background so that crawling can start before the sitemap is fully loaded.