# ztx

> node spiders

Latest version **1.0.15** (published 2018-05-26) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.15 |
| Published | 2018-05-26 |
| First published | 2018-05-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | jerremyzhang |

## Links

- npm: https://www.npmjs.com/package/ztx
- npm.io page: https://npm.io/package/ztx

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [cheerio](https://npm.io/package/cheerio.md) ^1.0.0-rc.2
- [request](https://npm.io/package/request.md) ^2.87.0
- [is-generator-function](https://npm.io/package/is-generator-function.md) ^1.0.7

## Recent versions

- 1.0.15 (latest) — 2018-05-26
- 1.0.13 — 2018-05-26
- 1.0.12 — 2018-05-26
- 1.0.11 — 2018-05-26
- 1.0.10 — 2018-05-26
- 1.0.9 — 2018-05-26
- 1.0.8 — 2018-05-26
- 1.0.7 — 2018-05-25
- 1.0.6 — 2018-05-25
- 1.0.5 — 2018-05-25
- 1.0.4 — 2018-05-25
- 1.0.3 — 2018-05-25
- 1.0.2 — 2018-05-25
- 1.0.1 — 2018-05-25
- 0.0.1 — 2018-05-25
- … 1 more at https://npm.io/package/ztx/versions

## README

# node scrawl 

node spiders 

## Installation

```bash
npm install --save ztx
```

## Usage

### create spiders 
+ create spider directory in root dir
```bash
mkdir spiders
```
+ create spider files in directory extend ztx.Spider
```javascript
const Spider = require('ztx').Spider;
const import$ = require('ztx').import$;
const core = require('ztx').Core;

module.exports = class CnblogsSpider extends Spider {
    constructor() {
        super()
        this.name = "test cnblogs";
        this.start_urls = "https://www.cnblogs.com/cnblogs";
        //爬虫中间件 用于获取和处理parse 后的数据
        this.use((ctx, next) => {
            console.log(ctx.value);
            // next();
        });
    }

    * parse(res) {
        let $ = import$.load(res);
        let titles = $('.post-list-item .PostTitle');
        for (let i = 0; i < titles.length; i++) {
            yield $(titles[i]).text();
        }


        let $next = $('#pager>a').last();
        let nextUrl = $next.attr('href');
        //获取下一个链接的地址
        if (nextUrl) {
            core.nextRequest(nextUrl, this.parse);
        }

    }
}
``` 
+ start ztx 
```javascript
const app = require('ztx').Core;

app.start();
```

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