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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ksky521/html-picker

v1.0.0

Published

html picker

Readme

html-picker

Usage

const picker = require('@ksky521/html-picker');
picker(content, handlerMap);

handlerMap

handlerMap是抓取的数据结构,抓取后会按照handlerMap的数据结构产出json数据。定义handlerMap的抓取结构是由selectorhandler两个key组成的对象,例如:

{
    selector: '',
    handler: ''
}

selector

selector是跟jQuery(cheerio)的选择器,会在 父节点(上一个抓取结构) 下面查找子元素。

handler

handler 是处理函数,支持jQuery(cheerio)的函数,比如:text($.text())、html(默认,$.html())、attr:xxx(实际是$.attr('xxx'))

处理jQuery的函数外,还支持自定义函数,自定义函数接受两个参数,第一个是选择器之后处理的jQuery(cheerio)对象,第二个是全局的jQuery(cheerio)对象, handler必须要有返回数据,不然抓取的就是undefined

{
    selector: 'li',
    handler: function($li, $){
        return $li.eq(0).text();
    }
}

抓取结构示例

{
  content: {
    selector: '.box694 li',
    handler: 'text'
  }
}

上面的实际是查找页面.box94 li的节点,然后返回其text()内容,如果li是多个,那么是返回一个数组,最终会在callback函数获取data的格式是:

{
    content: []
}

再看一个复杂的:

{
  content: {
    selector: '.box694 li',
    handler: {
      ip: {
        selector: '.ip'
      },
      port: {
        selector: '.port'
      }
    }
  }
}

上面实际是抓取结构嵌套的示例,首先查找页面的.box94 li的节点,然后执行两个选择器:'.ip''.port',最后传递给callback的数据结构是:

{
    content: [{
        ip: 'xxx',
        port: 'xxx'
    },{
        ip: 'xxx',
        port: 'xxx'
    }, ...]
}

实例

var spider = require('../lib/spider');

spider.get('http://guangdiu.com', function(err, $) {
    $('.gooditem').each(function(i, e) {
        console.log($(e).find('h2').text().trim());
    });
});
var spider = require('../lib/spider');

var now = Date.now();
spider({
    proxy: 'http://42.62.61.245:80',
    uri: 'http://guangdiu.com',
    timeout: 5e3
}, function(error, data, req) {
    if (!error && data) {
        var t = Date.now();
        console.log(t - now);
    }
}, {
    item: {
        selector: '.gooditem',
        handler: {
            title: {
                selector: 'h2',
                handler: 'text'
            },
            prices: {
                selector: 'h2 .emphricepart',
                handler: 'text'
            },
            image: {
                selector: '.showpic img',
                handler: 'attr:src'
            }
        }
    }
});