detection-worm-js

1.3.2 • Public • Published

detection-worm-js

请求页面,并使用XPATH语法进行页面解析 (github)

安装

npm install -S detection-worm-js

引用

NodeJS

const dwj = require('detection-worm-js');
const Runner = dwj.WebLoader.Runner;
const xpath = dwj.XPath;

Runner("xxxxxx").then(res => {
    const xp = new xpath(res, true);
    const param = [ ];
    console.log(xp.selector(`xpath解析字符串`, param))
})

ES6

import { XPath, WebLoader, ObjectType } from 'detection-worm-js';

WebLoader.Runner("xxxxxx").then(res => {
    const xp = new XPath(res, true);
    const param = [ ];
    console.log(xp.selector(`xpath解析字符串`, param))
})

方法使用

使用ThreadPool可以结合ThreadWorker类使用:

main.js:

const { ThreadPool } = require('detection-worm-js');

const workerPool = new ThreadPool().setWorkerOption(
  { filename: './ChildWorker.js' }
).start(5);

for (let i = 1; i <= 100; i++) {
  workerPool.run(i, (err, result) => {
    // 回调函数
  })
}

ChildWorker.js:

const { AbstractWorker } = require('detection-worm-js');

class Test extends AbstractWorker {

    // 重写`task`方法
    // @param param是入参
    task(param) {
    }
}

new Test();

Package Sidebar

Install

npm i detection-worm-js

Weekly Downloads

4

Version

1.3.2

License

MIT

Unpacked Size

24.1 kB

Total Files

4

Last publish

Collaborators

  • zhichao.ren