如何从html文件中提取特定标题下的所有文本

问题描述 投票:-1回答:1

我正在尝试从html文件中提取特定标题下的所有文本。我想使用xmllint实用程序。我正在Linux环境中工作。

这里是html文件:https://kernelnewbies.org/Linux_3.6#Block

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="keywords" content="Linux, kernel, operating system, changes, changelog, file system, Linus Torvalds, open source, device drivers">
<meta name="description" content="Summary of the changes and new features merged in the Linux kernel during the 3.6 development cycle">
<meta name="robots" content="index,nofollow">

<title>Linux_3.6 - Linux Kernel Newbies</title>
<script type="text/javascript" src="/moin_static199/common/js/common.js"></script>

<script type="text/javascript">
<!--
var search_hint = "Search";
.............
.............
<h1 id="Block">5. Block</h1>
<span class="anchor" id="line-118"></span><ul><li><p class="line862">Add a new operation code (BLKPG_RESIZE_PARTITION) to the BLKPG ioctl that allows altering the size of an existing partition, even if it is currently in use <a class="http" href="http://git.kernel.org/linus/c83f6bf98dc1f1a194118b3830706cebbebda8c4">(commit)</a> <span class="anchor" id="line-119"></span></li><li><p class="line862">Device mapper RAID: Add support for MD RAID10 <a class="http" href="http://git.kernel.org/linus/63f33b8dda88923487004b20fba825486d009e7b">(commit)</a> <span class="anchor" id="line-120"></span></li><li><p class="line862">Device mapper thin: add read-only and fail I/O modes <a class="http" href="http://git.kernel.org/linus/e49e582965b3694f07a106adc83ddb44aa4f0890">(commit)</a> <span class="anchor" id="line-121"></span></li><li><p class="line862">Device mapper: remove persistent data debug space map checker <a class="http" href="http://git.kernel.org/linus/3caf6d73d4dc163b2d135e0b52b052a2b63e5216">(commit)</a> <span class="anchor" id="line-122"></span></li><li><p class="line862">md/raid1: prevent merging too large request <a class="http" href="http://git.kernel.org/linus/12cee5a8a29e7263e39953f1d941f723c617ca5f">(commit)</a> <span class="anchor" id="line-123"></span><span class="anchor" id="line-124"></span></li></ul><p class="line867">
.............
.............
        },
        clickWrapper: function () {
          if ( ($(this).attr('href') === location.hash)
               || !('onhashchange' in window.document.body) ) {
            setTimeout(function () { $(window).trigger("hashchange"); }, 1);
          }
        },
      };
      $('#pagebox a[href^="#"]:not([href="#"])').on("click", mdAnchorFix.clickWrapper);
      $(window).on("hashchange", mdAnchorFix.jump);
      if (location.hash) setTimeout(function () { mdAnchorFix.jump(); }, 100);
    }(jQuery);
  </script>

  <!-- End of JavaScript -->
</body>
</html>

我想要以下输出:

5. Block

    Add a new operation code (BLKPG_RESIZE_PARTITION) to the BLKPG ioctl that allows altering the size of an existing partition, even if it is currently in use (commit)

    Device mapper RAID: Add support for MD RAID10 (commit)

    Device mapper thin: add read-only and fail I/O modes (commit)

    Device mapper: remove persistent data debug space map checker (commit)

    md/raid1: prevent merging too large request (commit)

[基本上,我想创建一个脚本,用于从内核新手网站中提取不同内核版本中对块层的更改的描述。

参考网址:https://kernelnewbies.org/Linux_3.6#Block

javascript html xmllint
1个回答
1
投票

正如您对问题的评论中提到的那样,您可以使用xidel而不是xmllint来获得大部分信息。所以试试这个:

 xidel https://kernelnewbies.org/Linux_3.6 --extract '//h1[@id="Block"]//following-sibling::ul[1]//p/text()'
© www.soinside.com 2019 - 2024. All rights reserved.