如何通过cheerio访问shadow dom的内容

问题描述 投票:1回答:1

当使用axios执行GET请求时,我检索以下HTML正文:

request:
   axios.get(URL)
        .then((response) => result = response.data)

body of 'result':
   <body>
       <custom-component></custom-component>
   </body>

通过Chrome检查custom-component时,我看到有很多孩子想访问。

例如:

<custom-component>
   <div class="header-container">...</div>
</custom-component>

通常通过cheerio,我可以通过以下方式访问该内容:

const $ = await cheerio.load(result);
$('.header-container')

但是,由于它是阴影组件,因此上面的代码不起作用。

对此有任何解决方法吗?

javascript http axios cheerio
1个回答
0
投票

你不能。您应该使用puppeteer库来获取在运行时创建的内容。https://github.com/puppeteer/puppeteer/issues/858#issuecomment-441429302

© www.soinside.com 2019 - 2024. All rights reserved.