title: Save HTML Source Code to File
body: <p>How can I copy the source code of a website into a text file in Python 3?</p>
  
  <p>EDIT:
  To clarify my issue, here's what I have:</p>
  
  <pre><code>import urllib.request
  
  def extractHTML(url):
      f = open('temphtml.txt', 'w')
      page = urllib.request.urlopen(url)
      pagetext = page.read()
      f.write(pagetext)
      f.close()
  
  extractHTML('http:www.google.com')
  </code></pre>
  
  <p>I get the following error for the f.write() function:</p>
  
  <pre><code>builtins.TypeError: must be str, not bytes
  </code></pre>