1. You need to start by syncing with the bitcoin blockchain (such as by running bitcoin core). You can then use software to parse the blockchain database (there's quite a lot of options available, as well as running the commands on the daemon yourself).
Your might face an issue if you're wanting a public key instead of an address though as they're only given when funds are spent from them and not when funds are received as those are sent to addresses (which are hashed forms of private keys).