这是一个 HTML 文件,在 HTML 文件中包含大量<section>... </section>内容,其格式如下。
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<section>
<div>
<header><h2>This is a title (RfQVthHm)</h2></header>
More HTML codes...
</div>
</section>
<section>
<div>
<header><h2>This is a title (UaHaZWvm)</h2></header>
More HTML codes...
</div>
</section>
<section>
<div>
<header><h2>This is a title (vxzbXEGq)</h2></header>
More HTML codes...
</div>
</section>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我需要提取第二个<section>...</section>内容。
这是预期的输出。
<section>
<div>
<header><h2>This is a title (UaHaZWvm)</h2></header>
More HTML codes...
</div>
</section>
Run Code Online (Sandbox Code Playgroud)
我注意到我可以先查找UaHaZWvm字符(以及前面 2 行),直到遇到下一个</section>.
OP的努力(在评论中提到): grep -o …