Get SSL certificate from website

Is it possible to run a test, that calls a website and then retrieves the SSL certificate (and especially the valid-to date of the certificate)?

We would like to check a dataset of websites and retrieve the validity of the websites and then perform a “calculation” that fails the test, if the certificate runs out in about 7 days.

is there a way to do this?

BR, George