Google offers a search API library to accomplish what you are trying to do. Implementing it will be much more complex than what you are currently trying.
To put it another way, what you get for "free" from Google is formatted HTML including their logo etc. If you want the underlying unformatted data, you will need to register for an API key with Google, and depending on how you are using the results and with what volume, there may be a monetary cost to use this service.
This article explains the process in more detail.
Google Search API: Everything You Need To Know[
^]