Helper for handle next-next page
$ npm i -S next-page-kit
const NextPageKit = require('next-page-kit')
options |
type | remark |
---|---|---|
options.charset |
type: String , allowedutf8 or gbk |
the page charset |
options.getCurrent |
function ($: cheerio) => any |
returns current paeg data |
options.hasNext |
function ($: cheerio) => Boolean |
test has next page |
options.getNext |
function ($: cheerio) => String |
get next page url |
const n = new NextPageKit({
getCurrent($) {
return $('img')
.map(function() {
return $(this).attr('src')
})
.toArray()
},
hasNext($) {},
getNext($) {},
})
// Promise<string[]>
// all img src
n.run()
url
: the entryoptions
:limit
: page limit
/// <reference types="cheerio" />
export type Charset = 'utf8' | 'gbk'
export default class NextPageKit<T> {
constructor(options: {
charset?: Charset
getCurrent($: CheerioStatic): T[] | T
hasNext($: CheerioStatic): boolean
getNext($: CheerioStatic): string
})
getCurrent($: CheerioStatic): T[] | T
hasNext($: CheerioStatic): boolean
getNext($: CheerioStatic): string
run(url: string, options?: {limit?: number}): Promise<T[]>
}
the MIT License http://magicdawn.mit-license.org