A programmable web crawler, which enables testing of web sites in Grafana k6 using the visitor pattern.
The JavaScript API allows you to create and easily program web crawlers.
In the callback functions of the crawler, custom logic can be used for testing.
The crawler is programmed using so-called callback functions. In the example above, two callback functions are registered.
With Crawler.onHTML, you can register a callback function that will run on HTML elements that match the selector parameter. The callback function parameter is the matching HTMLElement.
Normally, the Crawler.onHTML callback function is responsible for collecting the URLs to be crawled and placing them in a queue. This is usually done using the Request.visit function of the Request object belonging to the HTMLElement.
With the Crawler.onRequest callback function, you can customize the HTTP request before it is executed. The parameter of the callback function is the Request object.
c.onRequest((r) => { // ... });
The Crawler.onResponse callback function is called after the response has been received. The callback function parameter is the Response object.
c.onResponse((r) => { // ... });
The Crawler.visit function can be used to initiate the download of a given URL and the execution of registered callback functions.
Web crawler API for k6
A programmable web crawler, which enables testing of web sites in Grafana k6 using the visitor pattern. The JavaScript API allows you to create and easily program web crawlers. In the callback functions of the crawler, custom logic can be used for testing.
Example
The crawler is programmed using so-called callback functions. In the example above, two callback functions are registered.
With Crawler.onHTML, you can register a callback function that will run on HTML elements that match the selector parameter. The callback function parameter is the matching HTMLElement.
Normally, the Crawler.onHTML callback function is responsible for collecting the URLs to be crawled and placing them in a queue. This is usually done using the Request.visit function of the Request object belonging to the HTMLElement.
With the Crawler.onRequest callback function, you can customize the HTTP request before it is executed. The parameter of the callback function is the Request object.
The Crawler.onResponse callback function is called after the response has been received. The callback function parameter is the Response object.
The Crawler.visit function can be used to initiate the download of a given URL and the execution of registered callback functions.