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();