Node.js 用nodejs、cheerio刮去页码

Node.js 用nodejs、cheerio刮去页码,node.js,fetch,cheerio,Node.js,Fetch,Cheerio,如何从中提取数据 我的代码可以很好地处理一页,但我需要删除第2页、第3页的所有数据。。。然后进入电子书阵列 这是我的密码 function searchEbooks(query) { return fetch(getUrl(1, query)) .then(res => res.text()) .then(body => { const ebooks = []; $('article').

如何从中提取数据

我的代码可以很好地处理一页,但我需要删除第2页、第3页的所有数据。。。然后进入电子书阵列

这是我的密码

function searchEbooks(query) {
    return fetch(getUrl(1, query))
        .then(res => res.text())
        .then(body => {
            const ebooks = [];    
            $('article').each(function(i, element) {
                const $element = $(element);
                const $title = $element.find('.entry-title a');
                const $image = $element.find('.attachment-post-thumbnail');
                const $description = $element.find('.entry-summary');
                const authors = [];
                $(element).find('.entry-author a').each(function(i, element) {
                    author = $(element).text();
                    authors.push(author);
                });
                const ebook = {
                    image: $image.attr('src'),
                    title: $title.text(),
                    description: $description.text(),
                    authors: authors,
                }
                ebooks.push(ebook);
            });
            return ebooks;
        });
}
我不知道怎么做。请给我一个提示或一个例子

我使用cherrio,节点获取包


谢谢。

尝试此项以获取下一个url:

var href = $('.current+a').attr('href');

if(href){
    // you can check this url
} else {
    console.log('You get all page');
}
只需跟随[rel=next],直到它不再存在。