DOMCrawlingHelpers <Selection, Single>
Index
Methods
enqueueLinks
Parameters
optionaloptions: EnqueueLinksOptions
Returns Promise<AddRequestsBatchedResult>
extractLinks
Extracts URLs from the parsed DOM, without adding them to the request queue.
Parameters
optionaloptions: ExtractLinksOptions
Returns Promise<string[]>
parseWithCheerio
Returns Cheerio handle, allowing to work with the data same way as with CheerioCrawler. When provided with the
selectorargument, it will throw if it's not available.Example usage:
async requestHandler({ parseWithCheerio }) {const $ = await parseWithCheerio();const title = $('title').text();});Parameters
optionalselector: string
optionaltimeoutMs: number
Returns Promise<CheerioAPI>
querySelectorAll
Like
waitForSelector, but returns the matches in the form the parser produces them - a Cheerio object in CheerioCrawler. Throws when nothing matches.Parameters
selector: string
optionaltimeoutMs: number
Returns Promise<Selection>
querySelectorOne
Like
querySelectorAll, but returns only the first match.Parameters
selector: string
optionaltimeoutMs: number
Returns Promise<Single>
waitForSelector
Wait for an element matching the selector to appear. The
timeoutMsonly has an effect when the parser ismutable(e.g. JSDOMCrawler withrunScripts: true); otherwise the selector is checked once and the call resolves or throws immediately. Timeout defaults to 5s.Example usage:
async requestHandler({ waitForSelector, parseWithCheerio }) {await waitForSelector('article h1');const $ = await parseWithCheerio();const title = $('title').text();});Parameters
selector: string
optionaltimeoutMs: number
Returns Promise<void>
Helper function for extracting URLs from the parsed DOM and adding them to the request queue.