當爬蟲開始跟 restarted 的時候會觸發的事件
crawler.on("crawlstart", function() {
console.log("Crawl starting");
});
fetchstart (queueItem, requestOptions) - Fired when an item is spooled for fetching. If your event handler is synchronous, you can modify the crawler request options (including headers and request method.)
crawler.on("fetchstart", function(queueItem, requestOptions) {
console.log("fetchStart", queueItem);
});
抓取完成的時候會觸發的事件,responseBody 預設是 buffer,所以取值時要用 responseBody.toString()
。
crawler.on("fetchcomplete", function(queueItem, responseBody, responseObject) {
console.log("fetchcomplete", queueItem);
console.log("body", responseBody.toString());
});
當抓取時發生 HTTP error 的時候會觸發的事件
crawler.on("fetcherror", function(queueItem, responseObject) {
console.log("fetch error!");
});
當爬蟲已經沒有東西可以爬,而且 queue 都做完的時候會觸發的事件。
crawler.on("complete", function() {
console.log("Finished!");
});