1.3.1 • Published 6 years ago
@ta11y/extract v1.3.1
@ta11y/extract
Extracts content from websites for running accessibility audits with ta11y.
Install
npm install --save @ta11y/extractUsage
The easiest way to use this package is to use the CLI.
const { extract } = require('@ta11y/extract')
extract('https://en.wikipedia.org')
.then((result) => {
console.log(result.summary) // overview of results (number of urls visited, success, error)
console.log(result.results) // detailed results keyed by url
})const { extract } = require('@ta11y/extract')
// example passing HTML directly
extract('<!doctype><html><body><h1>I ❤ accessibility</h1></body></html>')
.then((result) => {
console.log(result.summary) // overview of results (number of urls visited, success, error)
console.log(result.results) // detailed results keyed by url
// note that the result key for an HTML input is 'root' instead of url
})API
extract
Extracts the dynamic HTML content from a website, optionally crawling the site to discover additional pages and extracting those too.
Type: function (urlOrHtml, opts): Promise
urlOrHtmlstring URL or raw HTML to process.optsobject Config options.opts.browserobject Required Puppeteer browser instance to use.opts.crawlboolean Whether or not to crawl additional pages. (optional, defaultfalse)opts.maxDepthnumber Maximum crawl depth while crawling. (optional, default16)opts.maxVisitnumber? Maximum number of pages to visit while crawling.opts.sameOriginboolean Whether or not to only consider crawling links with the same origin as the root URL. (optional, defaulttrue)opts.blacklistArray<string>? Optional blacklist of URL glob patterns to ignore.opts.whitelistArray<string>? Optional whitelist of URL glob patterns to only include.opts.gotoOptionsobject? Customize thePage.gotonavigation options.opts.viewportobject? Set the browser window's viewport dimensions and/or resolution.opts.userAgentstring? Set the browser's user-agent.opts.emulateDevicestring? Emulate a specific device type.- Use thenameproperty from one of the built-in devices.- Overrides
viewportanduserAgent.
- Overrides
opts.onNewPagefunction? Optional async function called every time a new page is initialized before proceeding with extraction.
License
MIT © Saasify