Cheerio多次请求

时间:2017-08-11 12:43:13

标签: javascript node.js request cheerio

我尝试从一个页面检索链接,然后提出其他请求来获取想要的页面。打印出响应体直接起作用,但新的cheerio实例不起作用。它只是打印一个空行。见下面的代码

const request = require('request')
const cheerio = require('cheerio')

const baseUrl = '...'

request(`${baseUrl}/...`, (error, response, articles) => {
  if (error) {
    console.log(error)
  } else {
    const $ = cheerio.load(articles)

    $('.feedArticleList')
      .children('li')
      .each((i, el) => {
        const link = $(el).children('a').attr('href')
        request(baseUrl + link, (error, response, article) => {
          if (error) {
            console.log(error)
          } else {
            console.log(article) // this works
            const $2 = cheerio.load(article)
            console.log($2('.Text').text()) // this just prints a blank line
          }
        })
      })
  }
})

0 个答案:

没有答案