# flexible

> Easily build flexible, scalable, and distributed, web crawlers.

Latest version **0.1.20** (published 2013-10-23) · 0 weekly downloads

## Install

```sh
npm install flexible
pnpm add flexible
yarn add flexible
bun add flexible
```

Provides the command `flexible`.

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.20 |
| Published | 2013-10-23 |
| First published | 2013-02-17 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Eckardt Olson |
| Maintainers | eckardt |
| Keywords | flexible, web, html, paser, dom, document, crawler, spider, queue, distributed, postgres, postgresql, sql, database, eventemitter, evented, router, querystring, middleware, scalable, node, nodejs, node.js |

## Links

- npm: https://www.npmjs.com/package/flexible
- Repository: https://github.com/eckardto/flexible
- Issues: https://github.com/eckardto/flexible/issues
- npm.io page: https://npm.io/package/flexible

## Dependencies (8)

- [pg](https://npm.io/package/pg.md) *
- [async](https://npm.io/package/async.md) *
- [request](https://npm.io/package/request.md) *
- [optimist](https://npm.io/package/optimist.md) *
- [traverse](https://npm.io/package/traverse.md) *
- [htmlparser](https://npm.io/package/htmlparser.md) *
- [iconv-lite](https://npm.io/package/iconv-lite.md) *
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) *

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.1.20 (latest) — 2013-10-23
- 0.1.12 — 2013-04-26
- 0.1.11 — 2013-03-20
- 0.1.10 — 2013-03-18
- 0.1.1 — 2013-03-05
- 0.1.0 — 2013-03-03
- 0.0.5 — 2013-02-24
- 0.0.4 — 2013-02-20
- 0.0.3 — 2013-02-18
- 0.0.2 — 2013-02-17
- 0.0.1 — 2013-02-17

## README

### This project will soon be superseded by [node-web-crawler](https://github.com/eckardto/node-web-crawler).

Flexible Web Crawler
====================

Easily build flexible, scalable, and distributed, web crawlers for [node](http://nodejs.org).

## Simple Example

```javascript
var flexible = require('flexible');

// Initiate a crawler. Chainable.
var crawler = flexible('http://www.example.com/')
    .use(flexible.pgQueue('postgres://postgres:1234@localhost:5432/'))

    .route('*/search?q=', function (req, res, body, doc, next) {
        console.log('Search results handled for query:', req.params.q);
    })
    .route('*/users/:name', function (req, res, body, doc, next) {
        crawler.navigate('http://www.example.com/search?q=' + req.params.name);
    })
    .route('*', function (req, res, body, doc, next) {
        console.log('Every other document is handled by this route.');
    })

    .on('complete', function () {
        console.log('All of the queued locations have been crawled.');
    })
    
    .on('error', function (error) {
        console.error('Error:', error.message);
    });
```

## Features
* Asynchronous friendly, and evented, API for easily building flexible, scalable, and distributed web crawlers.
* An array based queue for small crawls, and a PostgreSQL based queue for massive, and efficient, crawls.
* Uses a fast, lightweight, and forgivable, HTML parser to ensure proper document compatibility for crawling.
* Component system; use different queues, a router (wildcards, placeholders, etc), and other components.

## Installation

```
npm install flexible
```

Or from source:

```
git clone git://github.com/eckardto/flexible.git 
cd flexible
npm link
```

## Complex Example / Demo

```
flexible 

Crawl the web using Flexible for node.
Usage: node [...]/flexible.bin.js

Options:
  --url, --uri                  URL of web page to begin crawling on.                        [string]  [required]
  --domains, -d                 List of domains to allow crawling of.                        [string]
  --interval, -i                Request interval of each crawler.                          
  --encoding, -e                Encoding of response body for decoding.                      [string]
  --max-concurrency, -m         Maximum concurrency of each crawler.                       
  --max-crawl-queue-length, -M  Maximum length of the crawl queue.                         
  --user-agent, -A              User-agent to identify each crawler as.                      [string]
  --timeout, -t                 Maximum seconds a request can take.                        
  --follow-redirect             Follow HTTP redirection responses.                           [boolean]
  --max-redirects               Maximum amount of redirects.                               
  --proxy, -p                   An HTTP proxy to use for requests.                           [string]
  --controls, -c                Enable pause (ctrl-p), resume (ctrl-r), and abort (ctrl-a).  [boolean]  [default: true]
  --pg-uri, --pg-url            PostgreSQL URI to connect to for queue.                      [string]
  --pg-get-interval             PostgreSQL queue get request interval.                     
  --pg-max-get-attempts         PostgresSQL queue max get attempts.
```

## API

#### flexible([options])
Returns a configured, navigated and or with crawling started, crawler instance.

#### new flexible.Crawler([options])
Returns a new Crawler object.

#### Crawler#use([component], [callback])
Configure the crawler to use a component.

#### Crawler#navigate(url, [callback])
Process a location, and have the crawler navigate (queue) to it.

#### Crawler#crawl([callback])
Have the crawler crawl (recursive).

#### Crawler#pause()
Have the crawler pause crawling.

#### Crawler#resume()
Have the crawler resume crawling.

#### Crawler#abort()
Have the crawler abort crawling.

### Events

* `navigated` (url)
Emitted when a location has been successfully navigated (queued) to.
* `document` (doc)
Emitted when a document is finished being processed by the crawler.
* `paused`
Emitted when the crawler has paused crawling.
* `resumed`
Emitted when the crawler has resumed crawling.
* `complete`
Emitted when all navigated (queued) to locations have been crawled.

## License
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

---
_Source: https://npm.io/package/flexible · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
