I'm looking for a way to edit HTML files from the command line similar to
awk, but using path expressions similar to
jq or pup. In particular, newlines, white space and other formatting details shouldn't matter.
So I'd like to say something like "delete everything between
<body> and first
<p> tag following it, and replace it with the this text" or "replace every
</p>, keeping the text in between". The rest of the document should remain unchanged.
A library for, say, Perl, Python or Haskell where I can do that easily with a few lines would also be fine (but I'd prefer a commandline tool).
Background: I want to use this to clean up lots of epub files with awkward formatting, bad language tags etc.