Is there a way to read the complete console output buffer and save it to a file?

I do not want to use redirection. I need to save the (already filled) complete output buffer (9999 lines), ideally using Python.