我有这样一句话:
async.mapLimit(urls, 10, getCertificatesFromPage, callback)
其中url是一个带url的数组,getCertificatesFromPage:
getCertificatesFromPage = (url, callback) ->
request url, (err, res, html) ->
$ = cheerio.load(html)
allRows = $('div.search-result-shop')
objCollector = []
allRows.each () ->
links = $(this).find('a')
obj =
companyName: $(this).find('.companyname').text()
pageDetailsUrl: ''
link: ''
for link in links
extractedLink = link.attribs.href
if extractedLink.includes('http')
obj.link = extractedLink
else
obj.pageDetailsUrl = nameSpace.pageName + extractedLink
objCollector.push obj
return objCollector
这不能很好地工作,因为我需要收集每页10页10页的所有对象,但我只收到50 * 10个链接还有更多
如何使用此代码才能使其正常工作?
答案 0 :(得分:1)
getCertificatesFromPage = (url, callback) ->
您没有在callback
功能中调用getCertificatesFromPage
。没有它,框架就无法知道工作何时完成。