I will give you several answers:
Just write a regular expression that match the header/footer.
Learn how to write regular expressions, and then try Answer 1 above. It is a really fun and exciting skill to have: http://docs.python.org/library/re.html#re-syntax
Try to ask on a online forum, and hope that someone can be bothered to answer you.
Follow these directions.
I did a footer removal on a PDF. The footer looks like this:
The pattern to match this might be built using the following parts:
() surround a part to match. So we need () around it all.
The first part is easy:
This match the first line. In order to skip ahead to the next line we match some whitespace. Tabs, spaces and newlines. A special code exists for this, namely \s. There may not be any whitespace, or a lot. A * after a pattern will make the pattern match from 0 to many times. So now we have:
The next few parts should now be obvious:
Next comes a page number. That can change so we match one or more digits instead. The code \d will match a digit. If we add a + it will match one or more digits:
Just a few finishing touches, and we are done:
I don't actually remember all these codes. I look them up when I need them. But some I do remember. Write a few regular expressions, and it will become easier every time.
Now it should be easy for you to write your own regular expression that match your examples.
One of them would be (have not tested, so it could be wrong):
But this might actually be useful to keep, to allow navigation in the book. It is a bookmark that you can navigate to from a table of contents.
Regular expressions are written using a rudimentary language, with synonyms and many different ways to express the same thing. Some ways may be better/smarter/prettier/more robust than others.