V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
magicdawn
V2EX  ›  Node.js

next-page-kit 爬下一页下一页这种页面的小工具

  •  
  •   magicdawn · 2016-06-25 12:40:34 +08:00 · 2708 次点击
    这是一个创建于 2833 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本文首发于 CNodejs.org https://cnodejs.org/topic/576e0babd3baaf401780bb5f

    ------------------- 原文--------------------

    RT. 就是下一页, 下一页这种...给抽象了一下... 这里有个抓取 V2EX 的栗子 https://github.com/magicdawn/next-page-kit/blob/v0.0.1/test/simple.js#L16 提供本页要干啥, 是否有下一页, 下一页地址... 最后得到一个结果...就是这样

    下面是 README ---------------------------------我是分割线-----------------------------

    next-page-kit

    Helper for handle next-next page

    Build Status Coverage Status npm version npm downloads npm license

    Install

    npm i next-page-kit -S
    

    API

    const NextPage = require('next-page-kit');
    

    n = new NextPage

    • init/postInit : hook function. return a promise is also supported
    • action/hasNext/getNext: the logic
    const n = new NextPage({
      init() {
    
      },
      postInit() {
    
      },
    
      action($) {
    
      },
      hasNext($) {
    
      },
      getNext($) {
    
      }
    });
    
    yield n.run()
    

    n.run

    n.run(url, options)
    
    • url: the entry
    • options:
      • enc: the html encoding
      • limit: page limit

    Changelog

    CHANGELOG.md

    License

    the MIT License http://magicdawn.mit-license.org

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   981 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:08 · PVG 06:08 · LAX 15:08 · JFK 18:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.