始终使用node.js + cheerio返回undefined

时间:2018-04-08 17:23:26

标签: node.js express cheerio

我试图获取img src但我一直未定义

<table id="video_jacket_info">
        <tbody>
            <tr>
                <td style="vertical-align: top;">
                    <div id="video_jacket">
                        <img id="video_jacket_img" src="link.image.com" border="0"></div>
                    <!-- end of video_jacket -->
                </td>
            </tr>
        </tbody>
    </table>

获取图片的代码始终返回undefined

axios.get(baseUrl).then(response => {
    let $ = cheerio.load(response.data, { ignoreWhitespace: true, xmlMode: true });
      console.log($('table.video_jacket_info > .video_jacket_img').attr('src'));
     // I followed @JJJ comment but still return undefined
      console.log($('table.video_jacket_info .video_jacket_img').attr('src'));
    });

  }).catch(err => {
     console.log(err);
  });

0 个答案:

没有答案