是否有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