python write request must be str not bytes

datafile = open(localfile, "w", encoding="utf-8")
datafile.write(page.text)
datafile.close()

Here is what the above code is Doing:
1. It’s opening a file called “localfile” in write mode.
2. It’s writing the contents of the page variable to the file.
3. It’s closing the file.

Now, if you open the localfile.html file in your browser, you should see the same page you saw when you viewed the URL in your browser.