img-crawler

0.0.2 • Public • Published

img-crawler

A Node module for downloading images to disk from a given URL.

Installation

    npm install img-crawler

Running the tests

From the module directory run:

    npm test

Without npm:

    make test

Usage

Download imgs from 'pearljam.com' and write them to the 'pj-imgs' directory. The dir will be created if not found and resolved to an absolute path.


     var crawler = require('img-crawler');
 var opts = {
     url: 'http://pearljam.com',
     dist: 'pj-imgs'
 };
 
 crawler.crawl(opts, function(err, data) {
     console.log('Downloaded %d from %s', data.imgs.length, opts.url);
 });    
</code>

The callback

Keeping inline with node convention the callback first accepts an error object followed by data representing the downloaded images. The err object will be provided if loading the web page fails. Failures are reported in the img responses.

Here's an example of a response:

    {
        imgs: [
            {
                src: 'img/a-img.png', 
                statusCode: 200,
                success: true,
                path: '/Users/radvieira/my-imgs/img/a-img.png'
            },
            {
                src: 'img/another-img.png', 
                statusCode: 404,
                success: false
            }            
        ]
    }
    

In this case the first image was downloaded and written to disk while the other failed. Notice how there is no path attribute for the failed download.

Readme

Keywords

none

Package Sidebar

Install

npm i img-crawler

Weekly Downloads

1

Version

0.0.2

License

BSD

Last publish

Collaborators

  • radvieira