<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          htmlparser2HTML/XML 解析器

          聯(lián)合創(chuàng)作 · 2023-09-21 23:15

          htmlparser2 是一個 fast & forgiving HTML/XML 解析器。

          npm install htmlparser2

          htmlparser2 的 live demo:https://astexplorer.net/#/2AmVrGuGVJ

          htmlparser2 本身提供了一個回調(diào)接口,允許以最小的分配來消耗文檔。為了獲得更符合人體工程學的體驗,可閱讀下面的 Getting a DOM。

          const htmlparser2 = require("htmlparser2");
          const parser = new htmlparser2.Parser({
              onopentag(name, attributes) {
                  /*
                   * This fires when a new tag is opened.
                   *
                   * If you don't need an aggregated `attributes` object,
                   * have a look at the `onopentagname` and `onattribute` events.
                   */
                  if (name === "script" && attributes.type === "text/javascript") {
                      console.log("JS! Hooray!");
                  }
              },
              ontext(text) {
                  /*
                   * Fires whenever a section of text was processed.
                   *
                   * Note that this can fire at any point within text and you might
                   * have to stich together multiple pieces.
                   */
                  console.log("-->", text);
              },
              onclosetag(tagname) {
                  /*
                   * Fires when a tag is closed.
                   *
                   * You can rely on this event only firing when you have received an
                   * equivalent opening tag before. Closing tags without corresponding
                   * opening tags will be ignored.
                   */
                  if (tagname === "script") {
                      console.log("That's it?!");
                  }
              },
          });
          parser.write(
              "Xyz <script type='text/javascript'>const foo = '<<bar>>';</ script>"
          );
          parser.end();

          Output (with multiple text events combined):

          --> Xyz
          JS! Hooray!
          --> const foo = '<<bar>>';
          That's it?!
          瀏覽 10
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  伊人一道本 | 欧美熟女性爱 | 中国亚州精品历史女人久久 | 欧美性猛交ⅩXXX富婆 | 成人美女视频在线观看18 |