是否有js/npm模块从HTML获取呈现的输出(不解析HTML)。例如说我有以下HTML:获取呈现的HTML输出
<div class="st_view recipe-tab ingredients st_view_first st_view_active" style="position: absolute; left: 0px;">
<h1 class="tab-hint">
Yields: <span itemprop="recipeYield" class="tab-hint-value">2 Servings</span>
</h1>
<ol>
<li itemprop="ingredients">1 <strong> Banana Nut Muffin Bar</strong>
</li>
<li itemprop="ingredients">3 tablespoons <strong>Vanilla Milkshake Protein Powder</strong>
</li>
<li itemprop="ingredients">1
<sup>1</sup>⁄
<sub>2</sub> tablespoons banana, mashed
</li>
<li itemprop="ingredients">
<sup>1</sup>⁄
<sub>2</sub> tablespoon unsweetened almond milk
</li>
<li itemprop="ingredients">1 teaspoon walnuts, crushed
</li>
<li itemprop="ingredients">
<sup>1</sup>⁄
<sub>4</sub> teaspoon banana extract
</li>
<li itemprop="ingredients">
<sup>1</sup>⁄
<sub>4</sub> teaspoon zero-calorie sweetener
</li>
<li itemprop="ingredients">Pinch of cinnamon
</li>
</ol> </div>
这使得下面的输出:
反正是有访问以上(不通过HTML实际上解析)渲染线?
如:var lineSix = getLineSixFromRenderedHTML(html);
编辑:我想这样做在节点JS服务器端环境(不使用jQuery),我不想来解析HTML要经过各个元素来构造我的输出。我只想访问渲染线(而不是HTML)。
你可以给该行分配一个'id'并使用它在javasript中进行选择吗? – user2027202827
你是什么意思?你想在你的html文档中获得第六个元素吗?因为你可以用一些简单的javascript做到这一点:https://www.w3schools.com/js/js_htmldom_document.asp –
@SimonHyll一般来说,请不要使用w3schools作为参考,使用MDN(例如https:// developer .mozilla.org/en-US/docs/Web/API/Document)或其他更有信誉的地方。 – mscdex