我想使用cheerio 获取div 的第一个childNode。我使用 javascript dom 操作来获取它。但无法在cheerio 上获取它。
我已经在开发工具中尝试过并得到了预期的结果。但我想通过使用cheerio来实现。
javascript
document.querySelector('.title_wrapper .subtext').childNodes[0].textContent;
我想从此元素中获取文本“PG”。
<div class="subtext">
PG
<span class="ghost">|</span>
<time datetime="PT121M">
2h 1min
</time>
<span class="ghost">|</span>
<a href="/search/title?genres=action&explore=title_type,genres&ref_=tt_ov_inf">Action</a>,
<a href="/search/title?genres=adventure&explore=title_type,genres&ref_=tt_ov_inf">Adventure</a>,
<a href="/search/title?genres=fantasy&explore=title_type,genres&ref_=tt_ov_inf">Fantasy</a>
<span class="ghost">|</span>
<a href="/title/tt0076759/releaseinfo?ref_=tt_ov_inf" title="See more release dates">25 May 1977 (USA)</a>
</div>
你几乎已经完成了,只需使用 [0] 来获取 javascript 节点:
$('.subtext')[0].childNodes[0].nodeValue.trim()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)