使用 cheerio 在节点 js 上解析

Parse on node js with cheerio

我在 cheerio

上解析 html 代码时遇到问题

这是我需要解析的代码

<dd style="">
<p><strong>Version: </strong>0.4.0 (3612) for Android 4.3+ (Jelly Bean MR2, API 18)</p>
<p><strong>Update on: </strong>2018-04-17</p>
<p><strong>Signature: </strong>3ec8cd69d71b7922e2a17445840866b26d86e283</p>

我需要解析0.4.0 (3612) for Android 4.3+ (Jelly Bean MR2, API 18),但是没有strong怎么只解析<p>

这是我的解析代码:

function parseFields ($) {

   const h2 = $('.faq_cat').attr('id');
   const info = $('meta[name="description"]').attr('content');
   const version = $('ddstyle[name="p"]').attr('version')


   const fields = {
     h2,
     info,
     version
   };

您可以使用 text 函数如下

$('dd').find('p').first().text();

或者,如果需要特定元素,则使用 eq 代替 first,例如

$('dd').find('p').eq(0).text();