npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

linuocc-spider

v1.0.3

Published

A Spider based on node encapsulation

Downloads

3

Readme

基于node的爬虫封装

1.安装

npm install linuocc-spider

2.使用

//导入linuocc-spider
const Spider = require("linuocc-spider");


//实例化spider
const spider = new Spider(["http://baidu.com"], {
  linkPoolMaxNum: 500,
  delayTime: 500,
  timeout: 3000,
  encoding: "utf8",
  fileTypesIgnored: ["js", "css", "json"],
  domainIgnored: ["github.com"],
  onlySite: true
});

//调用开始爬取方法,方法需要传入一个回调函数,回调函数有两个参数,一个是返回的数据,一个是触发下一次爬取的方法,数据处理完之后一定要调用next()方法,否则不会继续爬取
spider.start((res, next) => {
  console.log(res.url);
  
  next();
  
});

3.配置项

| 配置名 | 说明 | 类型 | 默认值 | | :--------------: | :--------------------------------------: | :-----: | :-------------------: | | linkPoolMaxNum | 链接池(存储待爬取链接的容器)最大容量, | number | 500 | | delayTime | 两次爬取之间的间隔(单位毫秒) | number | 0 | | timeout | 爬取超时时间 | number | 5000 | | encoding | 响应数据的编码方式 | string | utf8 | | fileTypesIgnored | 忽略爬取的文件类型 | array | ["js", "css", "json"] | | domainIgnored | 忽略爬取的域名,包括二级域名,默认为空 | array | [ ] | | onlySite | 是否只爬取本站点,默认为否,爬取其他站点 | boolean | false |

4.返回数据

spider.start(callback)

callback(result,next):回调函数
result:返回的结果,为一个对象

| 属性名 | 说明 | 类型 | | :----: | :------------------------: | :----: | | url | 当前爬取的页面url | string | | data | 当前爬取页面的全部html数据 | string |

​ result示例

{
	url:"http://www.baidu.com/a.php?a=b",
    data:'<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title></head><body></body></html>'
}
next:触发进行下一次爬取的方法

​ next示例

spider.start((res, next) => {
  console.log(res.url);
  /*
  这里进行业务处理
  */
  next();//处理完之后调用next方法
});

更新日志

1.0.3

过滤域名之后的哈希值

1.0.1

新增是否只爬取目标网站页面的配置项

好像可以做点事了(* ^ ▽ ^ *)

1.0.0

完成简单的功能,除了能爬,什么都做不了┓( ´∀` )┏