Как извлечь весь текст под конкретным заголовком из файла html - PullRequest
0 голосов
/ 04 февраля 2020

Я пытаюсь извлечь весь текст под определенным заголовком из файла 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)

По сути, я хочу создать скрипт, который извлекает описание изменений в блочном слое в разные версии ядра, с сайта Kernel Newbies.

URL для справки: https://kernelnewbies.org/Linux_3.6#Block

1 Ответ

1 голос
/ 07 февраля 2020

Как уже упоминалось в комментариях к вашему вопросу, вы можете пройти большую часть пути, используя xidel вместо xmllint. Так попробуйте это:

 xidel https://kernelnewbies.org/Linux_3.6 --extract '//h1[@id="Block"]//following-sibling::ul[1]//p/text()'
...