Extract page text rects using tool like fitz, check if the same text is up on the top and bottom of all pages using its rect which tells its position on the page, if repeats over many pages, u got ur header and footer, can employ regex as well for more accurate extraction.