我从未使用过 Cheerio,但我会假设(与其他刮刀一样),它只会执行您指向的页面。假设 Cheerio.load 返回类似 api 的 jquery,您可能需要执行类似的操作
$('a').each(function(index, a) {
//TODO: You may want to keep track here of which you have done, and not redo any.
request('http://arandomsite.com' + a.attr('href'), myPageProcessFunction);
});
显然,您还需要添加 iframe 之类的内容,以确保获得完整的结果。
为了澄清,这里是一些更新的代码:
request('http://arandomsite.com/', function responseFunction(error, response, html) {
if (!error && response.statusCode == 200){
var $ = cheerio.load(html);
$('a').each(function(index, a) {
request('http://arandomsite.com' + a.attr('href'), responseFunction);
});
};
});